0

For some reason, I can't find why my generic.xaml does not override default style.

Everything is contains in a Themes folder and Styles are still available via intellisense but I must set them manually on each controls, for example here on a ComboBox

<ComboBox
    Style="{StaticResource ComboBoxBase}"
    ItemContainerStyle="{StaticResource ComboBoxItemBase}"
    />

My Generic.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="ComboBox.xaml"/>
        <!--other resources goes here-->
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

My App.xaml

<Application.Resources>
    <ResourceDictionary Source="Themes/Generic.xaml"/>
</Application.Resources>

Part of the ResourceDictionary for the ComboBox :

<Style x:Key="ComboBoxBase" TargetType="{x:Type ComboBox}">
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="OverridesDefaultStyle" Value="True" />
    <Setter Property="Template">
    <!--other setters goes here-->

I wish I could have my Themes to be default everywhere.

thx

lecloneur
  • 424
  • 5
  • 20
  • 1
    Note that `Themes/Generic.xaml` is supposed to contain the default Styles of custom controls in a control library. There is no need to reuse that name for what you are doing here. – Clemens May 09 '19 at 05:39
  • which name are we talking about ? – lecloneur May 09 '19 at 05:42
  • 1
    Themes/Generic.xaml. Besides that, setting `x:Key` on a Style resource prevents that it's used as default Style. – Clemens May 09 '19 at 05:43
  • I don't need to reuse the name "Themes/Generic.xaml" in App.xaml ? – lecloneur May 09 '19 at 05:45
  • 1
    As already said, you only need to use the special name `Themes/Generic.xaml` for a ResourceDictioary that is supposed to contain the default Styles of custom controls in a control library. You can call yours how ever you like. – Clemens May 09 '19 at 05:46
  • the `x:key` solved the problem. My Themes/Generic.xaml, actually contains all my default style for my app, the combobox is retemplated for example. – lecloneur May 09 '19 at 05:50
  • 1
    Sure, I just wanted you tell you, that it is **not mandatory** to use that file name for your ResourceDictionary. That special file name is meant to serve a different purpose, hence your naming is a little confusing. – Clemens May 09 '19 at 05:52
  • Ok thank you. I thought it has to be named that way. But if merged in app.xaml, as I understand then the name doesn't matter. – lecloneur May 09 '19 at 05:57

0 Answers0