在后面的代码中的 RoutedCommand.Execute 中设置relativeSource CommandTarget
我有一个名为命令的静态类。其中的 RoutedCommands 之一称为ConfirmNoPrint。我想在自定义控件后面的代码中执行它,如下所示:
Commands.ConfirmNoPrint.Execute(null, [WHAT_DO_I_PUT_HERE]);
在自定义控件类中,我有一个 Binding 实例,其relativeSource 属性设置如下:
_mainControlBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(UserControl), 2);
我可以使用 _mainControlBinding 的属性之一来获取 IInputElement 的实例吗?需要作为 Commands.ConfirmNoPrint.Execute 的第二个参数传递?
ConfirmNoPrint 的命令绑定是我的自定义控件的父级,但它位于不同的程序集中。我无法添加对它的引用,因为它会导致循环引用。
我完全找错了树吗?
I have a static class called commands. One the RoutedCommands in it is called ConfirmNoPrint. I want to Execute it in code behind from my custom control like this:
Commands.ConfirmNoPrint.Execute(null, [WHAT_DO_I_PUT_HERE]);
In the custom control class I have an instance of Binding whose RelativeSource property is set like this:
_mainControlBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(UserControl), 2);
Can I use one of the properties of _mainControlBinding to get the instance of IInputElement I need to pass as the second parameter of Commands.ConfirmNoPrint.Execute ?
The command binding for ConfirmNoPrint is the parent of my custom control, but it is in a different assembly. I can't add a reference to it since it would cause a circular reference.
I am barking up the wrong tree entirely?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据定义,路由命令是路由的。如果我很好地理解您的问题,您只需将
this
作为命令的第二个参数传递(假设您进入控制类)。该命令将在可视化树中向上冒泡,直到遇到父级上的命令绑定。Routed commands are, by definition, routed. If I understand your problem well, you just have to pass
this
as the second parameter of your command (assuming you're into the control class). The command will be bubbling up the visual tree until it encounters the command binding on the parent.