2017-03-01 61 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}}" > 
...