我正在尝试弄清楚如何在我的WPF应用程序中编辑所有标签颜色。
希望我能在这里得到一些意见。
场景
目标
Enable Theming for End User
问题
How to edit alle labels at once, Where the Color is bound to the Custom Color Resource
先决条件
Custom Resource Color on all Labels
示例
<Label.Foreground>
<SolidColorBrush Color="{DynamicResource CustomLabelColor}"/>
</Label.Foreground>
最佳答案
您必须在 XAML 中使用 DynamicResource:
<Window.Resources>
<SolidColorBrush x:Key="CustomLabelColor" />
<Style TargetType="Label">
<Setter Property="Foreground" Value="{DynamicResource CustomLabelColor}" />
</Style>
</Window.Resources>
<StackPanel>
<Label Content="fsdaf"></Label>
<Label Content="fsdaf"></Label>
<Label Content="fsdaf"></Label>
<Label Content="fsdaf"></Label>
<Label Content="fsdaf"></Label>
</StackPanel>
并从代码中设置颜色:
this.Resources["CustomLabelColor"] = new SolidColorBrush(Colors.Aqua);
或者使用十六进制:
this.Resources["CustomLabelColor"] =
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF00AAFF"));
关于c# - 编辑 WPF 应用程序中的所有标签颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25158831/