2011-11-30 42 views
-2

我有一些背景顏色的按鈕,但是當我將此按鈕設置爲禁用時,它看起來像一個空的文本框。爲什麼這樣並且能否解決。當在WPF中禁用時,按鈕的行爲(視覺上)爲文本框

+0

它不足以回答你的問題,發佈一些代碼部分和按鈕 –

+0

<按鈕點擊=「Button_Click」 Grid.Column =「1」高度的畫面=「20」保證金=「0,159,98,132 「Background =」blue「IsEnabled =」False「> – Vikram

+0

也許字體的顏色與背景色相同? –

回答

1

您是否考慮過爲按鈕定義自己的模板?這是一個例子。
請參閱'觸發屬性= IsEnabled ...'部分。在這裏,您可以根據需要爲禁用的按鈕定義外觀。我建議玩所有的價值觀,並根據您的需求定義它。

<Style TargetType="Button"> 
    <Setter Property="OverridesDefaultStyle" Value="True"/> 
    <Setter Property="BorderBrush" Value="LightGray"/> 
    <Setter Property="BorderThickness" Value="0"/> 
    <Setter Property="Foreground" Value="White"/> 
    <Setter Property="HorizontalContentAlignment" Value="Center"/> 
    <Setter Property="VerticalContentAlignment" Value="Center"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="Button"> 
       <Border x:Name="bord" 
        CornerRadius="5" 
        BorderBrush="{TemplateBinding BorderBrush}" 
        BorderThickness="{TemplateBinding BorderThickness}" 
        TextElement.Foreground="{TemplateBinding Foreground}" 
        TextElement.FontWeight="{TemplateBinding FontWeight}"> 
        <Border.Background> 
         <LinearGradientBrush StartPoint="0 0" EndPoint="0 1"> 
          <GradientStop Color="Gray" Offset="0"/> 
          <GradientStop Color="DarkGray" Offset="0.5"/> 
          <GradientStop Color="Black" Offset="0.5"/> 
         </LinearGradientBrush> 
        </Border.Background> 
        <ContentPresenter Content="{TemplateBinding Content}" 
           HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
           VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
       </Border> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsMouseOver" Value="True"> 
         <Setter Property="Background" TargetName="bord"> 
          <Setter.Value> 
           <LinearGradientBrush StartPoint="0 0" EndPoint="0 1"> 
            <GradientStop Color="Gray" Offset="0"/> 
            <GradientStop Color="DarkGray" Offset="0.5"/> 
            <GradientStop Color="Black" Offset="0.5"/> 
            <GradientStop Color="Black" Offset="0.7"/> 
            <GradientStop Color="LightBlue" Offset="1"/> 
           </LinearGradientBrush> 
          </Setter.Value> 
         </Setter> 
        </Trigger> 
        <Trigger Property="IsPressed" Value="True"> 
         <Setter Property="BorderThickness" TargetName="bord" Value="2"/> 
        </Trigger> 
        <Trigger Property="IsEnabled" Value="False"> 
         <Setter Property="Background" TargetName="bord" Value="Peru"/> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
+0

非常感謝Markus。它的工作:) – Vikram

+0

不客氣:-) – Markus

相關問題