在应用样式(没有填充属性)时,我在找出为什么我的填充没有在按钮上得到尊重时遇到问题。
<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>
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么?
Padding控件的属性通常表示“内边距”,即分配给MarginControlTemplate 中元素的属性:
<ControlTemplate TargetType="Button">
<Border ...>
<ContentPresenter Margin="{TemplateBinding Padding}" .../>
</Border>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)