【发布时间】:2012-04-21 20:16:56
【问题描述】:
我有一个DataTemplate,它放入了ResourceDictionary,DataTemplate 中有一个按钮,我将这个DataTemplate 放入一个窗口中。现在我想将按钮命令绑定到windowViewModel 的属性,我该怎么做?
这是代码:
<DataTemplate DataType="{x:Type types:User}" x:Key="UserTemp">
<Grid >
<Button Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ????}, AncestorLevel=1}, Path=SelectLocationCommand}" />
</Grid>
</DataTemplate>
在 Window.xaml 中
<ContentControl x:Name="UserTemp" />
在 WindowViewModel 中:
public ICommand SelectLocationCommand
{
get {return new RelayCommand(selectLocationCommand); }
}
void selectLocationCommand()
{
_welcomeTitle = "AA";
}
【问题讨论】:
标签: wpf binding mvvm prism mvvm-light