wpf <DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding IsCheck,UpdateSourceTrigger=PropertyChanged}" x:Name="DTCB" Command="{Binding DataContext.SelectedCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="{Binding Cad_No}"> <CheckBox.InputBindings> <MouseBinding MouseAction="LeftClick" /> </CheckBox.InputBindings> </CheckBox> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn>怎么从第二行开始设置mouseaction
时间: 2024-01-11 21:02:51 浏览: 145
Dictionary<K,V>的使用-C#入门经典教程
你可以使用 `DataGrid.RowStyle` 来为每行设置样式,并在第二行及以后的行中添加 `MouseBinding`,如下所示:
```
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRow}">
<Border x:Name="DGR_Border" BorderThickness="1" BorderBrush="#E0E0E0" Margin="0,-1,0,0">
<SelectiveScrollingGrid>
<SelectiveScrollingGrid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</SelectiveScrollingGrid.ColumnDefinitions>
<SelectiveScrollingGrid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</SelectiveScrollingGrid.RowDefinitions>
<DataGridCellsPresenter SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" Grid.Column="1" x:Name="CellPresenter"/>
<DataGridDetailsPresenter SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" Grid.Column="1" Grid.Row="1" x:Name="DetailsPresenter"/>
<DataGridRowHeader Grid.RowSpan="2" SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" x:Name="RowHeader"/>
</SelectiveScrollingGrid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="DGR_Border" Property="Background" Value="#FFC5CBF9"/>
</Trigger>
<DataTrigger Binding="{Binding Cad_No}" Value="YOUR_VALUE_HERE">
<Setter TargetName="DTCB" Property="IsEnabled" Value="False"/>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="AlternationIndex" Value="1">
<Setter Property="Background" Value="#FAFAFA"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#F2F2F2"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#FFC5CBF9"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
```
在模板中,你需要使用 `ControlTemplate.Triggers` 来添加样式触发器。在这个例子中,我添加了一个数据触发器,当 `Cad_No` 的值等于你指定的值时,禁用 `CheckBox`。你需要将 `YOUR_VALUE_HERE` 替换为你想要使用的值。
阅读全文