在当前上下文中触发模板子事件?
有没有办法从当前上下文(即页面、窗口、用户控件等)中的数据模板内的视觉对象触发事件。
例如,我有一个包含按钮或列表框的数据模板。我希望当单击按钮或在 ListBox 中触发 ListBox.SelectionChanged 时,应在包含使用此 DataTemplate 的 ControlControl 的页面上声明事件处理程序。
有什么想法吗?
Is there a way to fire an event from a visual within a DataTemplate in the current context (i.e. Page, Window, UserControl etc.).
For example I have a DataTemplate that contains a button or a ListBox. I want that when the button is clicked or when ListBox.SelectionChanged is fired in the ListBox, the event handler should be declared on the Page that contains the ControlControl which uses this DataTemplate.
Any ideas?
使用路由命令。
Use RoutedCommands.