I want to use TabControl with MaterialDesignExtensions.I'm getting an error in the app.xaml. What's the point I'm missing?
Load Nugets:
MaterialDesignColors v1.2.7
MaterialDesignThemes.Wpf v3.2.0
MaterialDesignExtensions v3.2.0
App.xaml
<Application x:Class="MyApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml"
xmlns:culture="clr-namespace:MyApp.Cultures"
xmlns:local="clr-namespace:MyApp"
xmlns:controls="clr-namespace:MaterialDesignExtensions.Controls;assembly=MaterialDesignExtensions"
>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ResourceDictionary1.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/Generic.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignExtensions;component/Themes/MaterialDesignDarkTheme.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignExtensions;component/Themes/Generic.xaml" />
<!-- primary colors -->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="{StaticResource Primary100}"/>
<SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="{StaticResource Primary100Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="#244886"/>
<SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="{StaticResource Primary500Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="{StaticResource Primary600}"/>
<SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="{StaticResource Primary600Foreground}"/>
</ResourceDictionary>
<!-- accent color -->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.Lime.xaml" />
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="SecondaryAccentBrush" Color="{StaticResource Accent400}"/>
<SolidColorBrush x:Key="SecondaryAccentForegroundBrush" Color="{StaticResource Accent400Foreground}"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Error Message
An error occurred while finding the resource dictionary "pack://application:,,,/MaterialDesignExtension:component/Themes/Generic.xaml"
I found this workaround, just include directly the TabControl dictionary from the MaterialDesignExtension 3.2.0
<ResourceDictionary Source="pack://application:,,,/MaterialDesignExtensions;component/Themes/TabControlTemplates.xaml" />
Related
I want to change the theme of my project during the runtime. I want it to be Dark or Light mode. I am using MaterialDesign. There is a change of theme during runtime, but I cannot control the color. What is the point I missed?
My App.xaml Code
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ResourceDictionary1.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/Generic.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignExtensions;component/Themes/MaterialDesignLightTheme.xaml"/>
<!-- primary colors -->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="{StaticResource Primary100}"/>
<SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="{StaticResource Primary100Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="#244886"/>
<SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="{StaticResource Primary500Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="{StaticResource Primary600}"/>
<SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="{StaticResource Primary600Foreground}"/>
</ResourceDictionary>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignExtensions;component/Themes/MaterialDesignLightTheme.xaml"/>
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="{StaticResource Primary100}"/>
<SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="{StaticResource Primary100Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="#244886"/>
<SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="{StaticResource Primary500Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="{StaticResource Primary600}"/>
<SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="{StaticResource Primary600Foreground}"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
My MaterialDesignDarkTheme.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestMaterialExtensions.Themes"
xmlns:po="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
>
<ResourceDictionary.MergedDictionaries>
<!-- theme from MaterialDesignInXAML -->
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml"/>
<!-- additional resources -->
<ResourceDictionary>
<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="{StaticResource Primary100}"/>
<SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="{StaticResource Primary100Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="Red"/>
<SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="{StaticResource Primary500Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="{StaticResource Primary600}"/>
<SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="{StaticResource Primary600Foreground}"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
My MaterialDesignLightTheme.xaml
<ResourceDictionary.MergedDictionaries>
<!-- theme from MaterialDesignInXAML -->
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<!-- own themes -->
<!-- additional resources -->
<ResourceDictionary>
<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="{StaticResource Primary100}"/>
<SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="{StaticResource Primary100Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="Yellow"/>
<SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="{StaticResource Primary500Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="{StaticResource Primary600}"/>
<SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="{StaticResource Primary600Foreground}"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
My Change Theme Code
public void SetLightDark(bool isDark)
{
var resources = Application.Current.Resources.MergedDictionaries;
var existingResourceDictionary = Application.Current.Resources.MergedDictionaries
.Where(rd => rd.Source != null)
.SingleOrDefault(rd => Regex.Match(rd.Source.OriginalString, #"(\/MaterialDesignExtensions;component\/Themes\/MaterialDesign((Light)|(Dark))Theme)").Success);
var source = $"pack://application:,,,/MaterialDesignExtensions;component/Themes/MaterialDesign{(isDark ? "Dark" : "Light")}Theme.xaml";
var newResourceDictionary = new ResourceDictionary() { Source = new Uri(source) };
Application.Current.Resources.MergedDictionaries.Remove(existingResourceDictionary);
Application.Current.Resources.MergedDictionaries.Add(newResourceDictionary);
}
I solved the problem. The problem is that since I did not set the address paths of my xaml files in SetLightDark correctly, the address files I created could not be accessed at all.
Changing ThemeChange.cs Code
public void SetLightDark(bool isDark)
{
var resources = Application.Current.Resources.MergedDictionaries;
var existingResourceDictionary = Application.Current.Resources.MergedDictionaries
.Where(rd => rd.Source != null)
.SingleOrDefault(rd => Regex.Match(rd.Source.OriginalString, #"(\/Themes\/MaterialDesign((Light)|(Dark))Theme)").Success);
var source = $"pack://application:,,,/Themes/MaterialDesign{(isDark ? "Dark" : "Light")}Theme.xaml";
var newResourceDictionary = new ResourceDictionary() { Source = new Uri(source) };
Application.Current.Resources.MergedDictionaries.Remove(existingResourceDictionary);
Application.Current.Resources.MergedDictionaries.Add(newResourceDictionary);
}
previous paths
$"pack://application:,,,/MaterialDesignExtensions;component/Themes/MaterialDesign{(isDark ? "Dark" : "Light")}Theme.xaml"
\/MaterialDesignExtensions;component\/Themes\/MaterialDesign((Light)|(Dark))Theme)"
current path
#"(\/Themes\/MaterialDesign((Light)|(Dark))Theme)"
$"pack://application:,,,/Themes/MaterialDesign{(isDark ? "Dark" : "Light")}Theme.xaml"
... My theme.xaml files are in a folder named Themes under the project.
In my App.xaml I have the following code:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- primary color -->
<ResourceDictionary>
<!-- include your primary palette -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/Scroll.xaml" />
<ResourceDictionary Source="Styles/ComboBox.xaml" />
<ResourceDictionary Source="Styles/ComboBoxCanType.xaml" />
<ResourceDictionary Source="Styles/ComboBoxCanType1.xaml" />
<ResourceDictionary Source="Styles/ComboBox1.xaml" />
<ResourceDictionary Source="Styles/TextBox.xaml" />
<ResourceDictionary Source="Styles/TaskContextMenu.xaml" />
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.red.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="#E42F34"/>
<SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="#FFFFFF"/>
<!--<LinearGradientBrush x:Key="PrimaryHueMidBrush" EndPoint="1.5,1.5" StartPoint="0.5,0">
<GradientStop Color="#8E2E2F" Offset="0"/>
<GradientStop Color="#E43D47" Offset="1"/>
</LinearGradientBrush>-->
<!--#F14450-->
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="#F14450"/>
<SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="#FFFFFF"/>
<SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="#4D1DCF"/>
<SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="#FFFFFF"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
I want to have a specific control from the HandyControl UI (specifically the WaveProgressBar) and therefore I need these lines:
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
For it to work and load the control. However, if I do do this, it messes with my MaterialDesign controls and other default controls I have, so how can I set the theme for ONLY the WaveProgressBar? Any help would be appreciated!
Resources have scope.
You can merge those just for your control:
<WaveProgressBar ......>
<WaveProgressBar.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
Or as resources of a grid containing several of these controls.
Or as resources of a usercontrol containing a number of these controls.
And so on.
Having said that.
Styles and templates can be applied targetting a specific control and you seem to have a unique control there.
So you could grab the bits you need and put them in a style which sets template, property values etc just to WaveProgressBar. This would also likely be more efficient.
Context: I'm using Mahapps.Metro Flyouts with Material Design toolkits.
Problem: When a Flyout opens it is not positioned as specified. For example, if I set the Flyout to be at the Bottom of the Window it gets positioned at the vertical center.
I’ve set up the App.xaml to support both Mahapps and Material Design. I also do a mapping of the themes and accents for a consistent experience.
I took the configuration as shown in the MD WIKI. I got a Metro Window and my application uses various controls with Mahapps and Material Design styling – without any trouble. Only the flyouts don’t work correctly.
To isolate the problem I reduced my application to a minimum. Furthermore I took the example flyout from the Material Design Mahapps demo application.
While the demo application runs perfectly, it doesn’t work in the context of my application.
If I leave the Mahapps-MD compatibility stuff out of my App.xaml the flyout works correctly, but of course without the MD theming.
App.xaml:
<Application x:Class="Frontend.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Frontend"
StartupUri="MainWindow.xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d1p1:Ignorable="d"
xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:UiLogic="clr-namespace:EPM.Frontend.Logic;assembly=Frontend.Logic">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<UiLogic:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</ResourceDictionary>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
<!-- Material Design -->
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
<!-- Material Design: MahApps Compatibility -->
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.MahApps;component/Themes/MaterialDesignTheme.MahApps.Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.MahApps;component/Themes/MaterialDesignTheme.MahApps.Defaults.xaml" />
<!--<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.MahApps;component/Themes/MaterialDesignTheme.MahApps.Flyout.xaml" />-->
<ResourceDictionary Source="/Resources/Icons.xaml" />
<ResourceDictionary Source="Themes/Colors.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!-- MahApps Brushes -->
<SolidColorBrush x:Key="HighlightBrush" Color="{DynamicResource Primary700}"/>
<SolidColorBrush x:Key="AccentColorBrush" Color="{DynamicResource Primary500}"/>
<SolidColorBrush x:Key="AccentColorBrush2" Color="{DynamicResource Primary400}"/>
<SolidColorBrush x:Key="AccentColorBrush3" Color="{DynamicResource Primary300}"/>
<SolidColorBrush x:Key="AccentColorBrush4" Color="{DynamicResource Primary200}"/>
<SolidColorBrush x:Key="WindowTitleColorBrush" Color="{DynamicResource Primary700}"/>
<SolidColorBrush x:Key="AccentSelectedColorBrush" Color="{DynamicResource Primary500Foreground}"/>
<LinearGradientBrush x:Key="ProgressBrush" EndPoint="0.001,0.5" StartPoint="1.002,0.5">
<GradientStop Color="{DynamicResource Primary700}" Offset="0"/>
<GradientStop Color="{DynamicResource Primary300}" Offset="1"/>
</LinearGradientBrush>
<SolidColorBrush x:Key="CheckmarkFill" Color="{DynamicResource Primary500}"/>
<SolidColorBrush x:Key="RightArrowFill" Color="{DynamicResource Primary500}"/>
<SolidColorBrush x:Key="IdealForegroundColorBrush" Color="{DynamicResource Primary500Foreground}"/>
<SolidColorBrush x:Key="IdealForegroundDisabledBrush" Color="{DynamicResource Primary500}" Opacity="0.4"/>
</ResourceDictionary>
</Application.Resources>
</Application>
Window (reduced to the relevant stuff):
<Controls:MetroWindow x:Class="Frontend.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:EPM.Frontend"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
mc:Ignorable="d"
DataContext="{Binding Main, Mode=OneWay, Source={StaticResource Locator}}"
Title="electronic platform manager" Width="732" Height="452"
Background="{DynamicResource MaterialDesignPaper}"
BorderThickness="1"
BorderBrush="{DynamicResource AccentColorBrush}"
EnableDWMDropShadow="True">
<Controls:MetroWindow.Flyouts>
<Controls:FlyoutsControl x:Name="flyoutsControl">
<Controls:Flyout x:Name="LeftFlyout" Position="Bottom" Header="Settings" materialDesign:FlyoutAssist.HeaderColorMode="Accent" IsOpen="True" Height="80">
<local:FlyoutContent />
</Controls:Flyout>
</Controls:FlyoutsControl>
</Controls:MetroWindow.Flyouts>
</Controls:MetroWindow>
Packages I'm using:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommonServiceLocator" version="1.3" targetFramework="net46" />
<package id="EntityFramework" version="6.1.3" targetFramework="net46" />
<package id="MahApps.Metro" version="1.4.1" targetFramework="net46" />
<package id="MahApps.Metro.IconPacks" version="1.6.0" targetFramework="net46" />
<package id="MahApps.Metro.Resources" version="0.6.1.0" targetFramework="net46" />
<package id="MaterialDesignColors" version="1.1.3" targetFramework="net46" />
<package id="MaterialDesignThemes" version="2.2.1.750" targetFramework="net46" />
<package id="MaterialDesignThemes.MahApps" version="0.0.8" targetFramework="net46" />
<package id="MvvmLight" version="5.3.0.0" targetFramework="net46" />
<package id="MvvmLightLibs" version="5.3.0.0" targetFramework="net46" />
</packages>
Output:
After trying a few hours getting this to work I’ve still no clue what the problem could be. Any hint is highly appreciated.
Best regards,
Marcus
I have this in Brushes.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:SkinBox.Controls">
<SolidColorBrush x:Key="{x:Static controls:Keys.BackgroundBrushKey}"
Color="{DynamicResource {x:Static controls:Keys.BackgroundColorKey}}" />
</ResourceDictionary>
And use it like this in Generic.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SkinBox.Controls"
xmlns:system="clr-namespace:System;assembly=System">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Skins/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Brushes.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
The problem is that wpf freezes the brush so the DynamicResource has no effect.
Is there a clean way to solve this? I can only think of nasty hacks.
Thought of a workaround:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:SkinBox.Controls">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Skins/Yellow.Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Brushes.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
This still does not give true dynamic resources but it reapplies the brushes so that they update when applying the skin.
Removes the need for duplicating the brushes in every skin.
File app.xaml
<Application.Resources>
<ResourceDictionary>
<SolidColorBrush x:Key="appBrush" Color="Red"/>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
File Dictionary1.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTemplate x:Key="ct">
<Rectangle Fill="{StaticResource appBrush }"/>
</ControlTemplate>
</ResourceDictionary>
Then MainWindow uses the template defined.
<Control Template="{StaticResource ct}"/>
Run. It says cannot find appBrush. What's the problem?
Note, changing StaticResource to DynamicResource definitely lets it work. But what is the reason forcing me to make the change?
Change your App.xaml to this and it will work:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<SolidColorBrush x:Key="appBrush" Color="Red"/>
</ResourceDictionary>
<ResourceDictionary Source="Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
I believe it is related to how resources are merged together. In these type of situations, I always use a Brushes.xaml resource dictionary to define all my brushes, and merge that in ahead of any other resource dictionaries.