簡體   English   中英

應用樣式時不考慮 WPF 按鈕填充

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM