Note that there are some explanatory texts on larger screens.

plurals
  1. POStyle WPF normal Control depending on Windows Theme
    primarykey
    data
    text
    <p>I have read lots of thing about WPF Theme, Skin, Style etc... But there is still something I cannot achieve.</p> <p>I have custom controls, which are styled depending on the OS theme, by having a different style in each of the theme file (Aero.NormalColor.xaml, Luna.NormalColor.xaml or Aero2.NormalColor.xaml), this work like a charm.</p> <p>I don't load/force any theme in my App.xaml, each controls (like buttons) keep there style depending on the OS theme. So I see XP buttons on XP, Win7 buttons on windows 7 and Win8 buttons on Windows 8.</p> <p>I also have ResourceDictionaries which are loaded in the App.xaml that contains "named" (explicit x:Key) styles for different normal wpf controls. They look like this:</p> <pre><code>&lt;Style x:Key="BlackComboBox" TargetType="{x:Type ComboBox}"&gt;&lt;/Style&gt; </code></pre> <p>and I use them like this</p> <pre><code>&lt;ComboBox Style="{StaticResource BlackComboBox}"&gt;&lt;/ComboBox&gt; </code></pre> <p>So for now, my BlackComboBox is the same on every Windows (XP/7/8).</p> <p>What I try to achieve is to have a different Style for these normal Controls depending on the OS theme, without having to subclass the Control (I think it will be overkill to have a subclass for each control that will need an OS specific them), so BlackComboBox could be different on each OS. </p> <p>I have already tried to put a style with the same key in a theme file, but this doesn't seem to work.</p> <p>I have thought about loading at runtime a different ResourceDictionary containing the style for the desired OS version:</p> <ul> <li>But it looks like an ugly solution.</li> <li>I don't like having to check for System.Environment.OSVersion. </li> <li>And it will not be theme dependant, but OS dependent.</li> </ul> <p>For me the best way seems to be able to have "named" style in a Theme file that kind of overrides the one in the ResourceDictionaries.</p> <p>Thanks for the help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload