添加样式时Mahapps TextBox ClearTextButton缺失

时间:2017-03-01 10:46:46

标签: wpf styles mahapps.metro

所以这是我的控制器:

<TextBox 
    Width="398"
    Height="25"
    Margin="23,0,0,0"
    >
    <TextBox.Style>
        <Style TargetType="{x:Type TextBox}" >
            <Setter Property="Foreground" Value="Gainsboro"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Controls:TextBoxHelper.ClearTextButton" Value="True"/>
            <Setter Property="Padding" Value="0,1,0,0" />
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Foreground" Value="White"/>
                    <Setter Property="Controls:TextBoxHelper.ClearTextButton" Value="True"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </TextBox.Style>
</TextBox>

正如您所看到的,我添加了Property="Controls:TextBoxHelper.ClearTextButton" Value="True",但我仍然看不到这个Buttons unlen我删除了所有Triggers并将其添加到控制器中:

<TextBox 
    Width="398"
    Height="25"
    Margin="23,0,0,0"
    Controls:TextBoxHelper.ClearTextButton="True">
</TextBox>

1 个答案:

答案 0 :(得分:3)

您应将Style作为“MetroTextBox”Style的基础:

<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource MetroTextBox}" >
    <Setter Property="Foreground" Value="Gainsboro"/>
    <Setter Property="BorderBrush" Value="Transparent"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="Controls:TextBoxHelper.ClearTextButton" Value="True"/>
    <Setter Property="Padding" Value="0,1,0,0" />
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="Controls:TextBoxHelper.ClearTextButton" Value="True"/>
        </Trigger>
    </Style.Triggers>
</Style>

或隐含的:

<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}" >
...