如果不知道两者的关系,我会使用元素绑定.例如
<YourControl x:Name="CmdSrc" />
<Button Command={Binding ElementName=CmdSrc, Path=CmdProperty} />Run Code Online (Sandbox Code Playgroud)
您应该考虑控件提供命令的方法.在我看来有点奇怪.;)
问候
编辑
好的,这只是一个暗示.以防你没有考虑它.
这是绑定命令的另一种方法.我承认我没有测试它.但我认为以下内容也应该有效.
当Button在控件中时,您也可以使用相对绑定.
<YourControl>
<Button Command={Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type YourControl}}, Path=CmdProperty} />
</YourControl>Run Code Online (Sandbox Code Playgroud)
然后,您不需要控件的名称.我正在避免使用名字,以防止代码背后出现肮脏的变通方法.
是的,我知道这是某种偏执狂.;)
| 归档时间: |
|
| 查看次数: |
103 次 |
| 最近记录: |