Button behaving(visually) as textBox when disabled in WPF

I have a button with some background color, but when I set this button as disabled it looks like a empty textbox. Why is it so and can it be resolved.

Answers


Have you considered defining your own Template for the button. Here is an example. See section 'Trigger Property=IsEnabled...'. Here you can define the appearance as you need it for disabled buttons. I suggest to play with all values and define it for your needs.

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

Need Your Help

What is a fast grid implementation in mono?

.net mono grid

I do need sorting, filtering, row and column hiding, and column reordering.

check or change keyboard typing language from server or client side

c# javascript jquery asp.net keyboard

how can we check or change keyboard typing language from server or client side ?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.