Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I created simple button and applied style.

XML
<UserControl.Resources>
        <Style x:Key="MyBtnStyle" TargetType="{x:Type Button}">
            <Setter Property="FontSize" Value="12" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="Foreground" Value="Red" />           
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="Width" Value="20" />
            <Setter Property="Content" Value="X"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="BorderThickness" Value="1"/>
                    <Setter Property="BorderBrush" Value="#FF2B3C59"/>
                    <Setter Property="Background" Value="Green"/>
                </Trigger>
                <Trigger Property="IsPressed" Value="True">
                    <Setter Property="BorderThickness" Value="2"/>
                    <Setter Property="BorderBrush" Value="#FF2B3C59"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>


and here button:

XML
<Button Style="{StaticResource MyBtnStyle}" Name="button1" Click="button1_Click" ></Button>


so the problem is after IsMouseOver trigger fires, default win7 button style also fires.

So how I can prevent it from firing?
Posted

Hi,

you didn't overwrite the ControlTemplate - so the original template is still used and with it all it's triggers.

But: if you overwrite the ControlTemplate, you get rid of all default behaviours, but you have to define the complete layout including all behaviours on your own.

Cheers
Jürgen
 
Share this answer
 
Comments
evaldas86 30-May-10 13:16pm    
So there is no way to override behaviours only which I want? I have to provide complete template?
Jürgen Röhr 30-May-10 13:49pm    
To be precise: of course, you can overwrite any property, you want. But your code has not much to do, with what you intended, because the Button is just not as simple as you expected it to be (and this is true for other controls as well). To proove it, just take an unmodified Button and set it's background to something nasty (say: orange). Did you expect what you see?

To gain a better understanding, it's a good idea to follow John Simmons proposal; then you have the complete template and can modify it as you need. As an example: the buttons 'backing' consists of a Rectangle in a Border in a Grid in a Border; and each plays a role in animating the different states...
The only thing I can think of is it's because you haven't overridden the ENTIRE style/template. Microsoft has all of the standard templates available as a download, or if you have Expression Blend, you can just create a copy of the template.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900