Auto apply application-level resource-dictionary theme to all controls in program?
-
So lets say i have some theme dll called: "ThemeAssortment.dll". And in a test-program i reference that dll and in my App.xaml" i do: <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="ExpressionTheme.App" StartupUri="MainWindow.xaml"> <Application.Resources> <!-- Resources scoped at the Application level should be defined here. --> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/ThemeAssortment;Component/ColoredTheme.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application> So what do i need to do for this alone to auto-apply some styles to all controls in use in the application? If i do: <ScrollBar Style="{DynamicResource ScrollBar}" /> Then a scrollbar gets the appropriate scrollbar theme... but if i don't specify a Style... then one does not get automatically applied...
-
So lets say i have some theme dll called: "ThemeAssortment.dll". And in a test-program i reference that dll and in my App.xaml" i do: <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="ExpressionTheme.App" StartupUri="MainWindow.xaml"> <Application.Resources> <!-- Resources scoped at the Application level should be defined here. --> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/ThemeAssortment;Component/ColoredTheme.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application> So what do i need to do for this alone to auto-apply some styles to all controls in use in the application? If i do: <ScrollBar Style="{DynamicResource ScrollBar}" /> Then a scrollbar gets the appropriate scrollbar theme... but if i don't specify a Style... then one does not get automatically applied...
This is down to how you define a style - if you define the target type instead of the key, it will get applied. For instance:
<Style TargetType="ScrollBar">
<Setter Property="MinWidth" Value="17"/>
</Style>The key thing here is that no key has been added to the definition of the style.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
This is down to how you define a style - if you define the target type instead of the key, it will get applied. For instance:
<Style TargetType="ScrollBar">
<Setter Property="MinWidth" Value="17"/>
</Style>The key thing here is that no key has been added to the definition of the style.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
Thank you that worked perfectly :P