Luthervd
Luthervd

Reputation: 1406

Routed event from user control in MVVM application

I am stuck on integrating a user control into a mvvm application.

The user control is a custom calendar and was not wrtitten using MVVM principles (I don't want to re-write it in MVVM).

I have a mouse down event that is fired in the user control (Which is combination of three different user controls).

The event fired code looks like this:

public static readonly RoutedEvent DateEvent = 
    EventManager.RegisterRoutedEvent("dateEvent", RoutingStrategy.Bubble, 
    typeof(RoutedEventHandler), typeof(UserControl2));

public event RoutedEventHandler dateEvent
{
    add{AddHandler(DateEvent, value);}
    remove{ RemoveHandler(DateEvent, value);}
}

private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
{
    RaiseEvent(new RoutedEventArgs(UserControl2.DateEvent, this));
}

How do I subscribe to this routed event in my main app viewModel? I know it is not very MVVM but as I said I cant be doing with re-writing my user control.

I know that this event will bubble up the tree until it is marked as handled. I know to add a public void method to deal with the event - I'm just not sure how to implement the interception of the event in the first place.

Upvotes: 2

Views: 3696

Answers (1)

jtimperley
jtimperley

Reputation: 2544

I think you should read the RelayCommand section of this.

WPF MVVM Apps

Upvotes: 1

Related Questions