panhans
panhans

Reputation: 59

How to pass parameters in caliburn micro using a user control with custom routed events?

I have a usercontrol with a custom routed event:

public partial class DummyControl : UserControl
{
    public static readonly RoutedEvent ActionClickEvent = EventManager.RegisterRoutedEvent(
        "ActionClick",
        RoutingStrategy.Bubble,
        typeof(RoutedEventHandler),
        typeof(DummyControl));

    public event RoutedEventHandler ActionClick
    {
        add { this.AddHandler(ActionClickEvent, value); }
        remove { this.RemoveHandler(ActionClickEvent, value); }
    }

    public DummyControl()
    {
        this.InitializeComponent();
    }

    private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
        this.RaiseEvent(new RoutedEventArgs(ActionClickEvent,this));
    }
}

In my xaml I'm using a datagrid and I want to pass the SlectedItem to my ViewModel. But when the event gets triggered, the passed item is alway null. When trying the same with an button everything works fine.

<Cstm:DummyControl cal:Message.Attach="[Event ActionClick] = [Action Test(dataGrid.SelectedItem)]"/>

Don't know if this is a known bug or if I missed something. :\

Upvotes: 2

Views: 633

Answers (2)

panhans
panhans

Reputation: 59

Nope! It's a bug. I reported this issue and it will be solved in the next major release:

https://github.com/Caliburn-Micro/Caliburn.Micro/issues/363

Upvotes: 1

Gael
Gael

Reputation: 428

Caliburn.Micro does not support custom routed event in event definition. See this awnser to make it work with custom routed event https://stackoverflow.com/a/8471269/6346570.

Additionnaly, you have to use the full name with namespace and owner class to refer to your event in xaml. it would be Cstm:DummyControl.ActionClick

Upvotes: 0

Related Questions