npo*_*lli 4 wpf xaml background datatrigger
我想在属性更改时更改应用程序主窗口的背景颜色.我们有一个可以更改的营业日期,我想在预期更改时更改窗口背景.我已经设置了一个属性来告诉它.但是我可以在自行更改的窗口上设置样式数据触发器吗?或者我需要在app.xaml中执行此操作吗?
我最终做了德鲁建议的事情.除了我没有使用依赖属性.
<Window.Resources>
<SolidColorBrush x:Key="windowBGBrush" Color="Green"/>
<SolidColorBrush x:Key="windowBGBrushBusinessDateChanged" Color="Red"/>
</Window.Resources>
<Window.Style >
<Style TargetType="{x:Type Window}">
<Setter Property="Background" Value="{DynamicResource windowBGBrush}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsBusinessDateChanged}" Value="true">
<Setter Property="Background" Value="{DynamicResource windowBGBrushBusinessDateChanged}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Style>
Run Code Online (Sandbox Code Playgroud)
IsBusinessDateChanged是我的Viewmodel上的一个属性,由服务设置.我不确定为什么这么难.
| 归档时间: |
|
| 查看次数: |
16210 次 |
| 最近记录: |