Button style doesn''t appear

Hi!

I've created a ResourceDirectory with a ControlTemplate for a custom control. That ControlTemplate contains several buttons, each one with it's own style located in the same resource directory. When I'm using Blend everything works as expected, but in runtime the style for the buttons aren't used instead the default windows buttone style is used. The XAML is auto generated by Blend, but it looks something like this:

<ControlTemplate x:Key="CustomControlTemplate">

<Grid>

....

<Button Style="{DynamicResource=ButtonStyle" .. />

...

</Grid>

</ControlTemplate>

<Style x:Key="ButtonStyle">

<!-- Template setter and customization. -->

</Style>

I can solve this by removing the style from the resource directory and add a control template directly to the buttons, like this:

<ControlTemplate x:Key="CustomControlTemplate">

<Grid>

....

<Button ..>

<Button.Template>

<ControlTemplate>

<!-- Customize here-->

</ControlTemplate>

</Button.Template>

</Button>

...

</Grid>

</ControlTemplate>

But why doesn't the first solution work when I'm running my application?

[1967 byte] By [Kimmen] at [2008-1-9]
# 1

try this...

<Style x:Key="ButtonStyle">

<!-- Template setter and customization. -->

</Style>



<ControlTemplate x:Key="CustomControlTemplate">

<Grid>

....

<Button Style="{StaticResource=ButtonStyle" .. />

...

</Grid>

</ControlTemplate>

MarlonGrech at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified