wpf 子窗口调用主窗口控件
子窗口:
public delegate void RowSelectedHandler(); //首先在子窗口定义委托
注意,此委托定义在NameSpace下,不要定义在Class内,只有定义在NameSpace下的委托才会父窗口被找到
然后在子窗口下定义委托事件:
public event RowSelectedHandler SelectedEvent; //class内
定义一个方法执行委托事件:
private void RowSelectedEvent() { if (SelectedEvent != null) SelectedEvent(); }
然后在一个触发事件中调用这个方法:
private void ToggleButton_Click(object sender, RoutedEventArgs e) { try { ToggleButton toggleButton = sender as ToggleButton; if (toggleButton != null) { RowSelectedEvent(); } } catch(Exception ex) { } }
父窗口的构造函数中:
gridEpx.SelectedEvent += GridEpx_SelectedEvent;