Search code examples
c#wpfeventsexpression-blendeventtrigger

Custom Event Triggers in Blend


Hi I have been learning WPF with "Expression Blend 4" last few days and this is what I want to accomplish.

I have a Main Window which has a single custom button in it.

What I want to do is that when the Mouse Cursor is to the left side of the Window, I want the button to start its animation and move to my cursor. Alternatively, when the cursor is at the right side of the window, I want the button to move right.

I have created custom events for this. I already tested them with "MessageBox"s to pop up if I either move left or right. In actual fact I want them to animate left or right. But in order to create an animation timeline, I cant find my custom events on blend. Is there a way to go about this?

Partial Code Below

private event EventHandler MoveRightEvent;
private event EventHandler MoveLeftEvent;

    public MainWindow()
    {
        this.InitializeComponent();

        // Insert code required on object creation below this point.
    MoveRightEvent += new EventHandler(MainWindow_MoveRightEvent);
    MoveLeftEvent += new EventHandler(MainWindow_MoveLeftEvent);
    }

void MainWindow_MoveLeftEvent(object sender, EventArgs e)
{
    MessageBox.Show("Moved Left!!");
}

void MainWindow_MoveRightEvent(object sender, EventArgs e)
{
    MessageBox.Show("Moved Right!!");
}

Solution

  • You question was about EventTrigger (please note that in this case you must use RoutedEvent and not .NET Event) but your question is begging for custom Behavior as in this example: WPF Tutorial: Behaviors