我可以使用下面的代码导航到另一个视图。我想使用 tabControl 和自定义控件进行导航,但没有用于绑定 myCommand 的 Command 属性。那么如何将我的命令绑定到自定义控件?:
<Button Command="{Binding myCommand}" Content="Nav"/>
Run Code Online (Sandbox Code Playgroud)
1.还有绑定吗?
2.如何给自定义控件添加命令属性?
每个 UIElement 都有所谓的 InputBindings
输入绑定支持将命令绑定到输入设备。例如,MouseBinding 实现输入绑定,其中包括特定于鼠标设备的属性。
<Label Content="new">
<Label.InputBindings>
<MouseBinding Gesture="LeftClick"
Command="{Binding Path=myCommand}"
CommandParameter="smth"/>
</Label.InputBindings>
</Label>
Run Code Online (Sandbox Code Playgroud)
因此,与其注册新的 Command 和 CommandParameter DP 并处理事件以触发 Command,不如尝试使用开箱即用的功能