DataGridTemplateColumn

DataGridTemplateColumn

DataGridTemplateColumn自定义单元格样式

<DataGrid Grid.Row="0" Name="BasicRuleDataGrid" PreviewMouseWheel="BasicRuleDataGrid_OnPreviewMouseWheel"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
AutoGenerateColumns="False"
RowDetailsVisibilityMode="VisibleWhenSelected"
SnapsToDevicePixels="True"
EnableRowVirtualization="False"
AreRowDetailsFrozen="False"
SelectionMode="Single"
ScrollViewer.IsDeferredScrollingEnabled="True"
IsReadOnly="True"
ItemsSource="{Binding ElementName=ComRuleMDataGrid, Path=SelectedItem.BasicRulesBinding}"
>
<!--上方:需要告知在ComRuleMDataGrid(子)里面找,在VM(父)里面找找不到-->
<DataGrid.AlternatingRowBackground>
<SolidColorBrush Color="#EBF7FC"></SolidColorBrush>
</DataGrid.AlternatingRowBackground>
<!--列-->
<DataGrid.Columns>
<DataGridTextColumn Width="*" Header="基本规则名称" Binding="{Binding BasRuleNameBinding}" />
<DataGridTextColumn Width="*" Header="基本规则说明" Binding="{Binding CommentBinding}" />
<DataGridTemplateColumn Header="是否删除" Width="Auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button HorizontalAlignment="Center" Tag="{Binding}" Style="{StaticResource BtADDStyle}" Content="-" Click="ButtonListDelet_OnClick_BasicRule"></Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>

列表说明:
数据源ItemsSource绑定类的collection
选择项SelectedItem绑定类的一个对象(便于后台操作,自动)
显示绑定类中某一属性

05-11 16:01