[英]WPF button padding not respected when applying a style
在應用樣式(沒有填充屬性)時,我在找出為什么我的填充沒有在按鈕上得到尊重時遇到問題。
<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>
我在這里缺少什么?
控件的Padding
屬性通常表示“內部邊距”,即分配給 ControlTemplate 中元素的Margin
屬性:
<ControlTemplate TargetType="Button">
<Border ...>
<ContentPresenter Margin="{TemplateBinding Padding}" .../>
</Border>
</ControlTemplate>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.