I'm trying to apply the ExpressionDark theme from the Windows Presentation Foundation (WPF) CodePlex project.
I have added the file ExpressionDark.xaml
in a Themes
subfolder, and changed my App.xaml
file to reference this file :
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="Themes/ExpressionDark.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
When I run the program, the styles are applied to all controls but not the window itself. The window's background remains white. What I understand is that the style applies to Window
class, but not to derived class.
To workaround this issue, I've try to create a new style in my app.xaml
file, in order to inherits the Windows style for my custom window class :
<Application.Resources>
<ResourceDictionary>
<Style
TargetType="{x:Type local:MainWindow}"
BasedOn="{StaticResource {x:Type Window}}" />
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="Themes/ExpressionDark.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
The result is strictly identical.
I've also try the advise from WPF: Adventures in Theming (Part 2) . I added to my window definition :
<Window
x:Class="MyProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:MyProject.ViewModel"
Title="MainWindow"
Height="350"
Width="525"
Style="{DynamicResource {x:Type Window}}" />
No more success.
What is missing?
PS: don't know if it matters, but my window's child is a Grid.
Specify Background using dynamic resource in the Window XAML
<Window x:Class="HellowWorld.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Hellow World" Height="614" Width="821"
Background="{DynamicResource WindowBackgroundBrush}">
我上次检查主题中没有Window
样式。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.