我想在 IsMouseOver 触发器中更改矩形的背景颜色,这可能吗?
<Window>
<Window.Resources>
<DataTemplate x:Key="StackListViewItemTemplate">
<Grid>
<Rectangle RadiusX="5" RadiusY="5" >
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF000000" Offset="0"/>
<GradientStop Color="{Binding Path=Events.Colour}" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock FontSize="18pt" Grid.RowSpan="2" Text="{Binding Path=Events.Name}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</Grid>
</DataTemplate>
</Window.Resources>
<Grid >
<ListView ItemTemplate="{DynamicResource StackListViewItemTemplate}">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<!-- Here I want to set the background colour of the Rectangle in the DataTemplate -->
</Trigger>
<Trigger Property="IsSelected" Value="true">
<!-- Same here -->
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
</ListView>
</Grid>
</Window>
编辑:
<Setter Property="Background" Value="Yellow"/>
有没有办法将设置器的属性值绑定到子控件?