MaterialDesign Runtime Change Theme Wpf - wpf

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.

Related

MaterialDesignExtensions TabControl

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" />

Have a App.xaml ResourceDictionary.MergedDictionaries Theme affect only certain controls WPF

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.

How to make multiple SolidColorBrush refer to one color in ResourceDictionary?

I have a "ResourceDictionary1.xaml" file to control colors in "MainWindow.xaml" file (intended for skinning) and it is working fine.
To have flexibility over colors, i defined separate SolidColorBrush resource for each individual control. But most of the time multiple SolidColorBrush use same color for clean look.
Now when i want to change the color i need to change it in all SolidColorBrush resources. So i want to bind all the SolidColorBrush color to one Color resource. When i need full control i can just remove the binding and specify another color.
So i created color resource in ResourceDictionary file. But when trying to bind the color the Key does not show up in intelliSense of VisualStudio.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFWindow.Skins"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Color x:Key="DarkH">#444444</Color>
<Color x:Key="DarkM">#555555</Color>
<Color x:Key="DarkL">#666666</Color>
<sys:String x:Key="TitleName">My App</sys:String>
<sys:Double x:Key="TitleBarHeight">32</sys:Double>
<SolidColorBrush x:Key="CicleMOut" Color="#aaaaaa"/>
<SolidColorBrush x:Key="CicleMOver" Color="#dddddd"/>
<Thickness x:Key="CircleMargin">8</Thickness>
<SolidColorBrush x:Key="TitleBarMOut" Color="#555555"/>
<SolidColorBrush x:Key="TitleBarMOver" Color="#555555"/>
<SolidColorBrush x:Key="ExitMOut" Color="#555555"/>
<SolidColorBrush x:Key="ExitMOver" Color="#666666"/>
<SolidColorBrush x:Key="ExitCross" Color="#aaaaaa"/>
<Thickness x:Key="CrossMargin">12</Thickness>
<sys:Double x:Key="CrossThickness">2</sys:Double>
<SolidColorBrush x:Key="MaxiMOut" Color="#555555"/>
<SolidColorBrush x:Key="MaxiMOver" Color="#666666"/>
<SolidColorBrush x:Key="MaxiBox" Color="#aaaaaa"/>
<Thickness x:Key="BoxMargin">12</Thickness>
<sys:Double x:Key="BoxThickness">1</sys:Double>
<SolidColorBrush x:Key="MiniMOut" Color="#555555"/>
<SolidColorBrush x:Key="MiniMOver" Color="#666666"/>
<SolidColorBrush x:Key="MiniBar" Color="#aaaaaa"/>
<Thickness x:Key="BarMargin">12</Thickness>
<sys:Double x:Key="BarThickness">1</sys:Double>
<SolidColorBrush x:Key="TitleBrs" Color="#aaaaaa"/>
<sys:Double x:Key="TitleFontSize">14</sys:Double>
<SolidColorBrush x:Key="FrmBdy" Color="#666666" />
Say i want to bind SolidColorBrush color to DarkH color.
<SolidColorBrush x:Key="FrmBdy" Color="{Binding DarkH}" />
This doesn't work. I got to know, binding in this way is not possible.
Then is there any other way to make multiple brushes refer to one color?
Because when there are say 20 or more SolidColorBrush, changing colors in each brush to same color doesn't sound efficient and cannot use single SolidColorBrush for above said flexibility reason.
I am new to WPF and migrated from WinForms. Still trying to do some intermediate WPF stuff.
Thanks.
You was close
<SolidColorBrush x:Key="FrmBdy" Color="{StaticResource DarkH}" />

Using Material Design Toolkit, Flyouts in Mahapps Metro Window don't work correctly

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

WPF SolidColorBrush bind to another StaticResource

I have question about SolidColorBrush.
I have Resource:
<SolidColorBrush x:Key="Accent3" Color="#0093DD"/>
And I would like to bind another resource to this one like this:
<SolidColorBrush x:Key="AccentColorBrush" Color="{Binding Source={StaticResource Accent3}}" />
Both of them are in same file, AccentColorBrush is below Accent3.
How should I do that?
You can create a color and then bind it to both your colorbrush...something like this:
<Color x:Key="YourColor">#0093DD</Color>
<SolidColorBrush x:Key="Accent3" Color="{StaticResource YourColor}"/>
<SolidColorBrush x:Key="AccentColorBrush" Color="{StaticResource YourColor}" />

Resources