简体   繁体   English

触发器上的WPF样式边框粗细

[英]WPF Styling border thickness on trigger

I have the following style defined... 我定义了以下样式......

<!-- Blue Button -->
<Style x:Key="BlueButton" TargetType="{x:Type Button}">
  <Setter Property="OverridesDefaultStyle" Value="True"/>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="Button">                   
     <Border Name="border" 
        BorderThickness="2"
        Padding="4,2" 
        CornerRadius="5" 
        BorderBrush="{TemplateBinding BorderBrush}"
        Background="{TemplateBinding Background}">
      <Grid >
        <ContentPresenter 
        HorizontalAlignment="Center" 
        VerticalAlignment="Center" 
        Name="content"/>
      </Grid>
    </Border>
    <ControlTemplate.Triggers>
      <Trigger Property="IsMouseOver" Value="True">
        <Setter Property="Background" Value="{DynamicResource BlueGradientOver}"/>
        <Setter Property="BorderBrush" Value="White"/>
      </Trigger>
      <Trigger Property="IsEnabled" Value="False">
        <Setter Property="Background" Value="Black"/>
        <Setter Property="BorderBrush" Value="White"/>
        <!-- how do I set the BorderThickness here? -->
        <Setter Property="Foreground" Value="White"/>
      </Trigger>             
      <Trigger Property="IsPressed" Value="True">
        <Setter Property="Background" Value="{DynamicResource BlueGradient4}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource BlueGradient1}"/>
      </Trigger>
    </ControlTemplate.Triggers>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
  <Setter Property="SnapsToDevicePixels" Value="true"/>
  <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
  <Setter Property="Background" Value="{DynamicResource BlueGradient1}"/>
  <Setter Property="BorderBrush" Value="{DynamicResource BlueGradient2}"/>
  <Setter Property="Foreground" Value="White"/>
  <Setter Property="HorizontalContentAlignment" Value="Center"/>
  <Setter Property="VerticalContentAlignment" Value="Center"/>
  <Setter Property="TextBox.TextAlignment" Value="Center"/>  
  <Setter Property="FontFamily" Value="Trebuchet MS"/>
  <Setter Property="FontSize" Value="15pt"/>
  <Setter Property="Effect" Value="{DynamicResource KioskStandardDropShadow}" />
  <Setter Property="IsEnabled" Value="True"/>
</Style>

I'd like to change the BorderThickness property when a button is disabled, but I can't figure out how to do it. 我想在禁用按钮时更改BorderThickness属性,但我无法弄清楚如何执行此操作。

In your control template you are setting the BorderThickness to be 2! 在您的控件模板中,您将BorderThickness设置为2! It should be: 它应该是:

UPDATED 更新

<!-- Blue Button --> 
<Style x:Key="BlueButton" TargetType="{x:Type Button}"> 
  <Setter Property="OverridesDefaultStyle" Value="True"/> 
  <Setter Property="BorderThickness" Value="2" />
  <Setter Property="Template"> 
    <Setter.Value> 
      <ControlTemplate TargetType="Button">                    
    <Border Name="border"  
        BorderThickness="{TemplateBinding BorderThickness}"  
        Padding="4,2"  
        CornerRadius="5"  
        BorderBrush="{TemplateBinding BorderBrush}" 
        Background="{TemplateBinding Background}"> 
      <Grid > 
        <ContentPresenter  
        HorizontalAlignment="Center"  
        VerticalAlignment="Center"  
        Name="content"/> 
      </Grid> 
    </Border> 
    <ControlTemplate.Triggers> 
      <Trigger Property="IsMouseOver" Value="True"> 
        <Setter Property="Background" Value="{DynamicResource BlueGradientOver}"/> 
        <Setter Property="BorderBrush" Value="White"/> 
      </Trigger> 
      <Trigger Property="IsEnabled" Value="False"> 
        <Setter Property="Background" Value="Black"/> 
        <Setter Property="BorderBrush" Value="White"/> 
        <Setter Property="BorderThickness" Value="10" /> 
        <Setter Property="Foreground" Value="White"/> 
      </Trigger>              
      <Trigger Property="IsPressed" Value="True"> 
        <Setter Property="Background" Value="{DynamicResource BlueGradient4}"/> 
        <Setter Property="BorderBrush" Value="{DynamicResource BlueGradient1}"/> 
      </Trigger> 
    </ControlTemplate.Triggers> 
      </ControlTemplate> 
    </Setter.Value> 
  </Setter> 
  <Setter Property="SnapsToDevicePixels" Value="true"/> 
  <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/> 
  <Setter Property="Background" Value="{DynamicResource BlueGradient1}"/> 
  <Setter Property="BorderBrush" Value="{DynamicResource BlueGradient2}"/> 
  <Setter Property="Foreground" Value="White"/> 
  <Setter Property="HorizontalContentAlignment" Value="Center"/> 
  <Setter Property="VerticalContentAlignment" Value="Center"/> 
  <Setter Property="TextBox.TextAlignment" Value="Center"/>   
  <Setter Property="FontFamily" Value="Trebuchet MS"/> 
  <Setter Property="FontSize" Value="15pt"/> 
  <Setter Property="Effect" Value="{DynamicResource KioskStandardDropShadow}" /> 
  <Setter Property="IsEnabled" Value="True"/> 
</Style> 

Have you tried Expression Blend 4? 你试过Expression Blend 4吗? It has a very nice intuitive UI for dealing with behaviors and triggers and activities directly on the XAML. 它具有非常好的直观UI,可直接在XAML上处理行为,触发器和活动。 You should give it a try! 你应该试一试! Generating all that code will probably take you 5 minutes (including your border). 生成所有代码可能需要5分钟(包括边框)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM