添加样式时缺少 Mahapps TextBox ClearTextButton

Mahapps TextBox ClearTextButton missing when add style

这是我的控制器:

<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 直到我删除了所有 Triggers 并将其添加到控制器中:

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

您的 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}}" >
...