【发布时间】:2011-12-01 09:53:18
【问题描述】:
假设如下代码,
public class SomeViewModel{
ICommand ReloadCommand{get...}
ICommand SaveCommand{get..}
}
//SomeView.xaml
<SomeCustomControl Reload="ReloadCommand" Save="SaveCommand" /> //NOT SURE HOW??
//SomeCustomContro.xaml
<SomeCustomControl x:Name="someCustomControl">
<Button Command={Binding ElementName=someCustomControl, Path=Reload />
<Button Command={Binding ElementName=someCustomControl, Path=Save />
</SomeCustomControl>
//SomeCustomControl.xaml.cs
..... //NOT SURE HOW TO ALLOW BINDING TO A ICOMMAND ??
在我的 SomeCustomControl 中,我需要支持“在 xaml 中绑定 ICommand”。 我知道 DependencyProperties 可以像这样绑定,但在这种情况下我需要绑定 ICommand。
有人可以建议最好的方法吗? 任何建议的材料或链接都会有用,因为我缺少方向。
编辑 1) 我可以在 SomeCustomControl 中使用 DataContext SomeView。两者之间有更多我无法化解的逻辑和分离。我“必须”在 SomeCustomControl 中的某处维护 Reload/Save ICommands 的引用。
非常感谢。
【问题讨论】: