2010-09-08 58 views
2

我有以下的樣式定義WPF造型邊框厚度...上觸發

<!-- 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> 

我想改變BorderThickness財產當按鈕被禁用,但我想不出該怎麼辦它。

+0

爲什麼下來投票? – ocodo 2010-09-08 06:12:59

回答

2

在您的控件模板中,您將BorderThickness設置爲2!它應該是:

修訂

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

謝謝,我該如何設置觸發器和默認值? – ocodo 2010-09-08 05:49:17

+1

然後觸發器可以設置爲預期 - > rudigrobler 2010-09-08 06:04:54

+1

並且應該在頂部設置默認值(您當前有OverridesDefaultStyle的位置) - 類似於它在觸發! – rudigrobler 2010-09-08 06:05:47

0

您是否嘗試過Expression Blend 4?它具有非常好的直觀用戶界面,可直接處理XAML上的行爲和觸發器以及活動。你應該試試看!生成所有代碼可能需要5分鐘(包括您的邊框)。

+0

我擁有它,但編輯器非常基礎,我一般使用Visual Studio&Emacs,我更喜歡學習語法,而不是依賴代碼生成。 - 但是,對於做視覺材料非常有用。 – ocodo 2010-09-08 05:50:24