我有一个 WPF 数据网格。数据网格绑定到一个名为 Orders 的自定义类型列表。目前我在数据网格中的每一行都有一个切换按钮。
如果 Orders 的属性 MultiID (boolean) 为 true 但无法使其正常工作,我只希望在 rowheader 中有一个切换按钮。
在我的 DataGridRow 中,我尝试使用下一行中的注释掉部分,这似乎没有什么区别,因为每一行都有一个切换按钮。
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Blue"/>
</Trigger>
<!--<DataTrigger Binding="{Binding MultiID}" Value="True">
<Setter Property="HeaderTemplate" Value="{StaticResource rowdetailToggleButton}"/>
</DataTrigger>-->
</Style.Triggers>
我的数据网格
<!-- The data grid to display orders-->
<DataGrid DataContext="{Binding OrderBlock}"
x:Name="dataGridOrders"
ItemsSource="{Binding Orders}"
RowStyle="{StaticResource DG_Row}"
RowDetailsTemplate="{StaticResource DG_RowDetail}"
RowHeaderStyle="{StaticResource DG_RowHeader}"
RowDetailsVisibilityChanged="dataGridOrders_RowDetailsVisibilityChanged">
<DataGrid.RowHeaderTemplate>
<DataTemplate>
<ToggleButton x:Name="RowHeaderToggleButton"
Click="RowHeaderToggleButton_Click"
Cursor="Hand"/>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Orders.MultiID}" Value="False">
<Setter TargetName="RowHeaderToggleButton" Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</DataGrid.RowHeaderTemplate>
我的 DataGridRowHeader
<!-- Data Grid row with toggle button -->
<Style x:Key="DG_RowHeader" TargetType="{x:Type DataGridRowHeader}">
<Setter Property="Width" Value="35"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRowHeader}">
<Border x:Name="DGRH_Border"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="True">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Offset="0" Color="LightGray"/>
<GradientStop Offset="1" Color="WhiteSmoke"/>
</LinearGradientBrush>
</Border.Background>
<ContentPresenter Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我的数据网格行
<!-- Data grid formatting Grid Row template -->
<Style x:Key="DG_Row" TargetType="{x:Type DataGridRow}">
<Setter Property="Opacity" Value="1"/>
<Setter Property="Padding" Value="3,2,2,3"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRow}">
<Border x:Name="DGR_Border"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="True">
<Border.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="Transparent"/>
<GradientStop Offset="1" Color="Silver"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding StatusGood}" Value="Send">
<Setter TargetName="DGR_Border" Property="Background" Value="{StaticResource brushRowSend}"/>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Blue"/>
</Trigger>
<!--<DataTrigger Binding="{Binding MultiID}" Value="True">
<Setter Property="HeaderTemplate" Value="{StaticResource rowdetailToggleButton}"/>
</DataTrigger>-->
</Style.Triggers>
</Style>