我想创建一个具有“ItemsSource=ObservableCollection...”的 TreeView。
我为 TreeViewItem 创建了一个 Style,其中包含 DataGrid,控件绑定到 ObservableCollection 中的项目。例如,绑定到项目属性的 CheckBox。
我想创建一个触发器,以防项目属性具有特定值,它将更改控件的属性值:
<Style TargetType="{x:Type TreeViewItem}" x:Key="GridItemStyle" x:Name="GridItemStyle2">
<Setter Property="Template" >
<Setter.Value>
<ControlTemplate TargetType="{x:Type TreeViewItem}">
<Border Background="Red" BorderBrush="Yellow" BorderThickness="3" Margin="2,10,0,0">
<StackPanel Background="Red" Margin="10,10,10,10" Orientation="Horizontal">
<StackPanel.Triggers>
<Trigger Property="{Binding IsSucceed}" Value="True">
<Setter Property="Background" Value="Blue"/>
</Trigger>
</StackPanel.Triggers>
<TextBlock Margin="0,0,10,0" Text="{Binding Path=time, StringFormat={}\{0:dd/MM/yyyy hh:mm:ss:fff\}, Mode=OneWay}"/>
<TextBlock Margin="0,0,10,0" Text="{Binding milisecond}"/>
<TextBlock Margin="0,0,10,0" Text="{Binding address}"/>
<TextBlock Margin="0,0,10,0" Text="{Binding IsSucceed}"/>
<TextBlock Margin="0,0,10,0" Text="{Binding statues}"/>
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
由于触发器,运行时获取异常:
<Trigger Property="{Binding IsSucceed}" Value="True">
<Setter Property="Background" Value="Blue"/>
</Trigger>
我该如何解决?