2016-07-28 132 views
-1

我有以下的風格切換按鈕的邊框顏色不會更改?

<Style TargetType="{x:Type ToggleButton}" x:Key="ListToggleButton"> 
      <Setter Property="FontSize" Value="15" /> 
      <Setter Property="SnapsToDevicePixels" Value="True" /> 
      <Setter Property="Foreground" Value="#FF232A2E"/> 
      <Setter Property="Background" Value="White"/> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type ToggleButton}"> 
         <Border Background="{TemplateBinding Background}" BorderBrush="#FFECECEC" BorderThickness="0,0,0,1"> 
          <Grid> 
           <ContentPresenter x:Name="MyContentPresenter" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" /> 
          </Grid> 
         </Border> 
         <ControlTemplate.Triggers> 

          <Trigger Property="IsChecked" Value="False"> 
           <Setter Property="Background" Value="#FF232A2E"/> 
           <Setter Property="BorderBrush" Value="#FFECECEC"/> 
           <Setter Property="BorderThickness" Value="0,0,0,1"/> 
          </Trigger> 

          <Trigger Property="IsChecked" Value="True"> 
           <Setter Property="Background" Value="#FFF5F5F5"/> 
           <Setter Property="BorderBrush" Value="#FF25a0da"/> 
           <Setter Property="BorderThickness" Value="0,0,0,2"/> 
          </Trigger> 

         </ControlTemplate.Triggers> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 

我想改變邊框的顏色,當我檢查的按鈕,背景的變化,但不接壤!

我錯過了什麼提前

回答

1

您需要爲邊界指定一個名稱,並在SetterTargetName下指定它

感謝。當您省略TargetName時,它將設置觸發器所有者的屬性值(在本例中爲ToggleButton本身)。 Background setter正在工作,因爲邊框的背景是模板綁定到togglebutton的背景屬性。

<Style TargetType="{x:Type ToggleButton}" x:Key="ListToggleButton"> 
    <Setter Property="FontSize" Value="15" /> 
    <Setter Property="SnapsToDevicePixels" Value="True" /> 
    <Setter Property="Foreground" Value="#FF232A2E"/> 
    <Setter Property="Background" Value="White"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ToggleButton}"> 
       <Border x:Name="ButtonBorder" Background="{TemplateBinding Background}" BorderBrush="#FFECECEC" BorderThickness="0,0,0,1"> 
        <Grid> 
         <ContentPresenter x:Name="MyContentPresenter" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" /> 
        </Grid> 
       </Border> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsChecked" Value="False"> 
         <Setter Property="Background" Value="#FF232A2E"/> 
         <Setter Property="BorderBrush" Value="#FFECECEC" TargetName="ButtonBorder"/> 
         <Setter Property="BorderThickness" Value="0,0,0,1" TargetName="ButtonBorder"/> 
        </Trigger> 
        <Trigger Property="IsChecked" Value="True"> 
         <Setter Property="Background" Value="#FFF5F5F5"/> 
         <Setter Property="BorderBrush" Value="#FF25a0da" TargetName="ButtonBorder"/> 
         <Setter Property="BorderThickness" Value="0,0,0,2" TargetName="ButtonBorder"/> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
+0

非常感謝:)我適當的幫助。 –