<Style x:Key="CenteredTextBoxStyle" TargetType="{x:Type TextBox}">
    <Setter Property="FontSize" Value="16"/>
    <Setter Property="HorizontalAlignment" Value="Center"/>
    <Setter Property="VerticalAlignment" Value="Center"/>
</Style>

<Style x:Key="CenteredLabelStyle" TargetType="{x:Type Label}">
    <Setter Property="FontSize" Value="16"/>
    <Setter Property="HorizontalAlignment" Value="Center"/>
    <Setter Property="VerticalAlignment" Value="Center"/>
</Style>

使用方式:

<TextBox Style="{StaticResource CenteredTextBoxStyle}"/>
<Label Style="{StaticResource CenteredLabelStyle}"/>
``
WPF 写一个样式有水平居中垂直居中字体16文本框和标签控件都可以引用

原文地址: https://www.cveoy.top/t/topic/cv11 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录