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"></ Setter>
5 <Setter Property="TextWrapping" Value ="Wrap"></Setter>
6 </Style>
7 <!--标题 居中跨行-->
8 <Style TargetType ="DataGridColumnHeader" x: Key="dgHeader">
9 <Setter Property ="HorizontalContentAlignment" Value="Center"></Setter >
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 }"/>
时间: 2024-10-13 00:48:02