I have a DataTemplate that have put in a ResourceDictionary, and there is a button in the DataTemplate and I put this DataTemplate in a window. Now I want to bind the Button Command to a property of windowViewModel,how can I do that? this is the code:
<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> and in Window.xaml
<ContentControl x:Name="UserTemp" /> and in WindowViewModel:
public ICommand SelectLocationCommand { get {return new RelayCommand(selectLocationCommand); } } void selectLocationCommand() { _welcomeTitle = "AA"; }