Question

I have a custom control with a button in its template. Template is in my.xaml file referenced in themes\generic.xaml.

In my app, I use two styles for buttons: wide (default, keyless) and narrow (x:Key="narrowButton"). They are defined in myDic.xaml file.

I want the button in my template to be narrow.

But this doesn't work:

<ResourceDictionary ...>
<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/assembly;component/myDic.xaml" />
    <ResourceDictionary>
        <Style TargetType="{x:Type localui:MyControl}">
        <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type localui:MyControl}">
                <Button Style="{StaticResource narrowButton}">...</Button>
            </ControlTemplate>
        </Setter.Value>
        </Setter>
        </Style>
    </ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

In fact, MergedDictionaries in my.xaml causes the button to be not shown at all.

What is a working approach to apply the narrowButton style to my button?

Was it helpful?

Solution

Check the code below...

<ResourceDictionary ...>
   <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="/assembly;component/myDic.xaml" />
   </ResourceDictionary.MergedDictionaries>
         <Style TargetType="{x:Type localui:MyControl}">
              <Setter Property="Template">
                  <Setter.Value>
                      <ControlTemplate TargetType="{x:Type localui:MyControl}">
                            <Button Style="{StaticResource narrowButton}">...</Button>
                      </ControlTemplate>
                  </Setter.Value>
             </Setter>
          </Style>
</ResourceDictionary>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top