我已经定义了一个数据模板,它有一个触发器,如果选择了该项目,该触发器应该简单地改变背景颜色。由于某种原因,它似乎不起作用。
<DataTemplate x:Key="existingDeviceTemplate" >
<StackPanel Orientation="Horizontal">
<Border Name="bd" Background="Green" BorderThickness="1" Padding="5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Path=Name}" Width="200"/>
<Button Grid.Column="1" Content="Settings" Click="cmdSettings_Clicked"/>
<Button Grid.Column="2" Content="Delete" Click="cmdDelete_Clicked"/>
</Grid>
</Border>
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsSelected}" Value="true" >
<Setter TargetName="bd" Property="Background" Value="Red"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>