在我的 App.xaml 中,我有以下内容(只是一个例子):
<Style Class="Banner" TargetType="Label">
<Setter Property="TextColor" Value="#00ff00" />
<Setter Property="BackgroundColor" Value="#0000ff" />
<Setter Property="FontSize" Value="30" />
</Style>
这适用于:
<Label StyleClass="Banner" Text="Hello" />
但是,如果我使用深色/浅色主题之一,则会忽略“横幅”样式类。我希望我创建的 StyleClass 能够添加到主题中。
我希望能够“增强”主题,这可能吗?
我已经设法让这个工作。在我的 App.xaml 中,我有...
<!-- Enhancements to the Dark theme -->
<ResourceDictionary x:Name="EnhancedDark">
<Style Class="Banner" TargetType="Label">
<Setter Property="TextColor" Value="#000000" />
<Setter Property="BackgroundColor" Value="#ffffff" />
<Setter Property="FontSize" Value="Large" />
</Style>
...
</ResourceDictionary>
<!-- Enhancements to the Light theme -->
<ResourceDictionary x:Name="EnhancedLight">
<Style Class="Banner" TargetType="Label">
<Setter Property="TextColor" Value="#ffffff" />
<Setter Property="BackgroundColor" Value="#000000" />
<Setter Property="FontSize" Value="Large" />
</Style>
...
</ResourceDictionary>
然后在我的 app.cs 中设置具有增强功能的 Dark 主题
Resources.MergedDictionaries.Add(new DarkThemeResources());
Resources.MergedDictionaries.Add(EnhancedDark); // Important
Resources.MergedDictionaries.Remove(EnhancedLight); // Important
光也类似。现在在我的代码中,我可以:
<Label StyleClass="Banner" ... />
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句