2017-03-01 20 views
0

所以这是我的控制器:Mahapps文本框ClearTextButton丢失时添加样式

<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> 
+0

这个问题可能是你在找什么: http://stackoverflow.com/questions/32230427/extending-textbox-in-wpf-using-mahapps-保持风格 – petric

回答

2

您应该对 “MetroTextBox” Style基地的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}}" > 
...