如何在DataGrid WPF中更改单元格选择的背景 [英] how to change the cell selected background in DataGrid WPF

查看:85
本文介绍了如何在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)


这篇关于如何在DataGrid WPF中更改单元格选择的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆