using attached events with caliburn micro Message.Attach

前端 未结 3 1087
借酒劲吻你
借酒劲吻你 2020-12-01 13:01

I\'m trying to use caliburn micro message to trigger an attached event that I created:

public static class DataChanging
{

    public delegate void DataChang         


        
3条回答
  •  一整个雨季
    2020-12-01 13:43

    Have you tried this?

    cal:Message.Attach="[Event Changing] = [Action SelectedDataChanged($eventArgs)]"
    

    I needed to send an event from a child control to the parents ViewModel, and it worked fine for me. I'll post some example code maybe it'll help someone out!

    Child Control codebehind:

    public partial class MyControl : UserControl
    {
        public MyControl()
        {
            InitializeComponent();
        }
    
        #region Routed Events
    
        public static readonly RoutedEvent ControlClosedEvent = EventManager.RegisterRoutedEvent(
            "ControlClosed",
            RoutingStrategy.Bubble,
            typeof(RoutedEventHandler),
            typeof(MyControl));
    
        public event RoutedEventHandler ControlClosed
        {
            add { AddHandler(ControlClosedEvent, value); }
            remove { RemoveHandler(ControlClosedEvent, value); }
        }
    
        #endregion Routed Events
    
        private void Close(object sender, RoutedEventArgs e)
        {
            var rea = new RoutedEventArgs(ControlClosedEvent);
            RaiseEvent(rea);
        }
    }
    

    Child control XAML:

    Parent view:

    
    

提交回复
热议问题