WPF 样式示例:水平垂直居中,字体大小16
<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>
<p>使用方法:</p>
<pre><code class="language-xaml"><TextBox Style='{StaticResource CenteredTextBoxStyle}'/>
<Label Style='{StaticResource CenteredLabelStyle}'/>
</code></pre>
原文地址: https://www.cveoy.top/t/topic/nwxn 著作权归作者所有。请勿转载和采集!