WPF DataGridRow在触发器上更改子控件的属性
本文关键字:控件 属性 DataGridRow 触发器 WPF | 更新日期: 2023-09-27 18:26:27
我有一个这样的网格:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20px" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="200px" />
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0" IsChecked="{Binding IsChecked, Mode = TwoWay}" VerticalAlignment="Center">
</CheckBox>
<StackPanel Grid.Column="1" Orientation="Vertical" >
<Label Content="{Binding property1}" ></Label>
<Label Content="{Binding property2}" ></Label>
</StackPanel>
<Button Grid.Column="2" Content="Click it" x:Name="myCoolbutton" Command="{Binding Parameter}"/>
</Grid>
如果网格的行上有MouseOver事件,我的计划是更改按钮的Visibility属性。事实上,我尝试过用风格触发器,但我无法达到我的目标,如果有人能给我一个提示,那将是令人愉快的。
谢谢
编辑:以下是我以前工作的一些例子-这是一个评论,因为它不能正常工作
<Grid.Style>
<Style TargetType="{x:Type Grid}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<!-- <EventSetter Event="MouseMove" Handler="{Binding Rowhover}"></EventSetter>-->
<!-- <Setter Property="Opacity" Value="0.5"></Setter>-->
</Trigger>
<!--<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=Control,AncestorLevel=1}, Path=IsMouseOver}" Value="True" >
<Setter Property="Visibility" Value="Hidden" />
</DataTrigger>-->
<!--<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=Control,AncestorLevel=1}, Path=IsMouseOver}" Value="True">
<Setter TargetName="copyToClipboardButton" Property="Visibility" Value="Hidden" />
</DataTrigger>-->
</Style.Triggers>
</Style>
将此样式添加到按钮,当鼠标位于网格上方时,将执行EnterActions属性,否则将执行ExitActions;通过将子控件的Data绑定到其祖先之一的事件,有效地更改了子控件属性。
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=Grid},Path=(IsMouseOver)}" Value="True">
<Setter Property="SomeChildControlProperty" Value="SomeValue" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=Grid},Path=(IsMouseOver)}" Value="False">
<Setter Property="SomeChildControlProperty" Value="SomeValue" />
</DataTrigger>
</Style.Triggers>
</Style>