Xavier
Xavier

Reputation: 359

What is wrong with this WPF trigger

I have this XAML code that throws an exception (It just says it threw it, no name).

I googled around and found http://social.msdn.microsoft.com/Forums/en/wpf/thread/cfb159dc-d58e-41c2-81b5-c52e1272c0ce. Which says that any change made on a used property throws an exception.

So is it impossible to set a trigger in the <Control.Style> ?

I'm sure it's a very noob mistake as I am learning this technology.

XAML code

<Window x:Class="Triggers.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Button>
        <Button.Style>
            <Style TargetType="Button">
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" >
                        <Setter Property="Opacity" Value="0.7" />
                    </Trigger>
                </Style.Triggers>                      
            </Style>
        </Button.Style>
        Meow
    </Button>
</Grid>

Upvotes: 0

Views: 87

Answers (1)

Matt Burland
Matt Burland

Reputation: 45155

It's because you haven't told the trigger what value the property IsMouseOver should have?

Try this:

<Trigger Property="IsMouseOver" Value="True">

The thing to remember is the "IsMouseOver" is a property, not an event. So it can be either true or false and you need to tell WPF which state your trigger applies to.

Upvotes: 2

Related Questions