如何在DataGrid WPF中更改单元格选择的背景
问题描述:
我如何设置选定单元格的背景颜色,即当一个单元格获得焦点时,它应该能够以编程方式设置背景颜色.
2.如何以编程方式将DataGrid的TextBoxcolumn(单元格)中的文本对齐到左居中或右居
3.如何通过单击鼠标选择一个单元格
最好的问候
伊克巴尔
在此先感谢
How i can set the background color of a selected cell ie when a cell gets focus it should be able set the background color programmatically.
2. How I Can align the text in TextBoxcolumn(cells)in a DataGrid to left center or right programmatically
3. How I can select a cell by single mouse click
Best regards
Iqbal
Thanks in advance
答
希望这会有所帮助:
Hope this helps:
<DataGrid AutoGenerateColumns="False"
Margin="12"
Name="dataGrid1"
SelectionUnit="Cell">
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Red" />
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Header="Nombre"
Binding="{Binding Nombre}">
<DataGridTextColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment"
Value="Center" />
</Style>
</DataGridTextColumn.HeaderStyle>
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment"
Value="Right" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Apellido"
Binding="{Binding Apellido}">
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
现在包括标题Alignment:o)
Now includes header Alignment :o)