Blend 4 Beta: How to Change Image Source as Part of the Timeline

I am trying to complete a Blend 4 form and am looking for a way to do a simple thing:

  • When the mouse hovers over an image, the image should change its source to another image. When that happens MouseLeave, the image will change.

I know that I can do this in the source code, but I'm looking for a free code way to do this without manually coding xaml.

Blend 4 seems like the perfect fit. But I tried to set this using event triggers that fire stories or use Visual States, but Blend doesn't seem to “remember” that the image source has changed. He remembers how I change other properties of the image (for example, visibility, scale, etc.), but the source of the image is what I need.

Is this a mistake in the mix, or am I doing something wrong?

+3
source share
2 answers

One option is to create a custom action and bind it to the image. It still includes code, but is a bit alike.

public class ImageSwitchAction : TriggerAction<Image>   
{
    public ImageSource TargetImage { get; set; }
    protected override void Invoke(object o)
    {
        AssociatedObject.Source = TargetImage;
    }
}

After adding a class to the project and creating it, you can drag the new behavior onto any image objects on the timeline and configure the trigger and ImageSource in the action properties. In your case, add one action for MouseEnter and one for MouseLeave.

+2
source

simple way:

first, subscribe to the events of your mouse and mouse image, and then in these events

image.setsource( URI ( URL- )),

,

-2

Source: https://habr.com/ru/post/1743195/


All Articles