在wpf中引发传递参数的事件
我想在双击 GridView 中的项目时向窗口添加选项卡。但将添加的选项卡取决于单击的项目。我应该在 WPF 上以哪种方式执行此操作?我考虑过 RoutedEvents,但我不知道如何用它传递参数。有什么建议吗?
I'd like to add tabs to my window when an item in the GridView is double-clicked. But the tab that will be added depends on the clicked item. Which way should I do this on WPF? I thought about RoutedEvents, but I don't know how to pass a parameter with it. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这篇代码项目文章介绍了如何使用新的
RoatedEvent
和与RoatedEventArgs
不同的参数类型(相当远的位置,搜索“Second using custom RoutedEventArgs”),尽管我希望 WPF 包含一个RoatedEventHandler
版本,如 CLR 的事件处理程序其中 T : EventArgs
因此您不必每次都声明一个新的委托。摘要:
This codeproject article covers using a new
RoutedEvent
with a different argument type than justRoutedEventArgs
(rather far down, search for "Second using custom RoutedEventArgs"), though I wish WPF included a version ofRoutedEventHandler
like the CLR'sEventHandler<T> where T : EventArgs
so you didn't have to declare a new delegate every time.The summary:
使用命令而不是路由事件:
为单击的项目设置命令,并使用 XAML 中的relativesource 绑定将单击的项目的引用作为命令的参数传递。
Use commands rather than routed events:
Set a command for the clicked item and pass the clicked item's reference as the command's parameter using RelativeSource binding in the XAML.