解决XAML DataGrid文本居中-技术&分享

定义样式style:dgCell

<Window.Resources>
        <XmlDataProvider x:Key="AllItem" />
        <Style x:Key="dgCell" TargetType="{x:Type TextBlock}">
            <Setter Property="TextAlignment" Value="Center"/>
        </Style>
</Window.Resources>

引用样式style:dgCell

<controls:DataGridTextColumn Header="序号"  Width="40" Binding="{Binding XPath=@id}" ElementStyle="{StaticResource ResourceKey=dgCell}" />

运行效果


发布了40 篇原创文章 · 获赞 4 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/jackson0714/article/details/25045795