1在全局App.xaml文件中声明

在<ResourceDictionary></ResourceDictionary>标记中
添加 <ResourceDictionary Source="TableStyle.xaml"/>
2在TableStyle.xaml文件的< ResourceDictionary></ResourceDictionary>标记中加入
 1  <!--表格模版 -->
 2     <!--单元格 文本居中 跨行-->
 3     <Style TargetType ="TextBlock" x: Key="dgCell">
 4         <Setter Property ="TextAlignment" Value="Center"/>
 5      <Setter Property="TextWrapping" Value ="Wrap"/>
 6     </Style>
 7     <!--标题 居中跨行-->
 8     <Style TargetType ="DataGridColumnHeader" x: Key="dgHeader">
 9         <Setter Property ="HorizontalContentAlignment" Value="Center"/>
10         <Setter Property ="ContentTemplate">
11             <Setter.Value>
12                 <DataTemplate>
13                    <TextBlock Text ="{Binding}" TextWrapping="Wrap"   TextAlignment ="Center"   HorizontalAlignment="Center"/>
14                 </DataTemplate>
15             </Setter.Value>
16         </Setter>
17     </Style>

 

3在前台页面.xaml文件中绑定数据源
在<DataGridTextColumn/>标记中添加
即为
1 <DataGridTextColumn ElementStyle ="{StaticResource dgCell }" HeaderStyle ="{ StaticResource dgHeader }"/>

 

相关文章:

  • 2021-11-22
  • 2021-12-04
  • 2022-12-23
  • 2021-08-12
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
猜你喜欢
  • 2021-07-16
  • 2021-11-26
  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
相关资源
相似解决方案