[英]WPF button padding not respected when applying a style
I'm having issues finding out why my padding is not being respected on the button when applying a style (with no padding attribtues).在应用样式(没有填充属性)时,我在找出为什么我的填充没有在按钮上得到尊重时遇到问题。
<Style x:Key="NoHoverDisabledButton" TargetType="{x:Type Button}">
<Setter Property="Background" Value="#ccc"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Button Style="{StaticResource ResourceKey=NoHoverDisabledButton}" Padding="20,0" x:Name="OnlineUpdateButton" Width="Auto" HorizontalAlignment="Right" BorderThickness="0" Height="32" VerticalAlignment="Top" FontSize="14">
<StackPanel Orientation="Horizontal">
...
</StackPanel>
</Button>
What am I missing here?我在这里缺少什么?
The Padding
property of a control is typically meant to represent an "inner margin", ie be assigned to the Margin
property of an element in the ControlTemplate:控件的Padding
属性通常表示“内部边距”,即分配给 ControlTemplate 中元素的Margin
属性:
<ControlTemplate TargetType="Button">
<Border ...>
<ContentPresenter Margin="{TemplateBinding Padding}" .../>
</Border>
</ControlTemplate>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.