Jesse Hallam
Jesse Hallam

Reputation: 6964

Why does this Trigger not fire?

<Image Source="Data\Images\close_nohover.bmp">
    <Image.Style>
        <Style TargetType="{x:Type Image}">
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Source" Value="Data\Images\close_hover.bmp" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Image.Style>
</Image>

Upvotes: 2

Views: 510

Answers (1)

Fredrik Hedblad
Fredrik Hedblad

Reputation: 84647

Since the trigger changes the Source Property, the Source must be set within the Style and not explicitly on the Image. Like this

<Image>
    <Image.Style>
        <Style TargetType="{x:Type Image}">
            <Setter Property="Source" Value="Data\Images\close_nohover.bmp"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Source" Value="Data\Images\close_hover.bmp" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Image.Style>
</Image>

Upvotes: 3

Related Questions