The goal is to directly access the properties in the child ViewModel without losing the context of the entire ViewModel structure.
I currently have a resource in a dictionary that contains a link to the ViewModel, which I use as the data context for the entire application.
So my datacontext for each view is as follows:
DataContext="{StaticResource mainViewModel}"
In my ViewModel model, I have nested child ViewModels, for example:
public class ParentViewModel {
public ChildVM ChildVM { get; set; }
public ParentVM(){
ChildVM = new ChildViewModel();
}
}
public class ChildViewModel {
public string SomeProperty { get; set; }
}
In my opinion, I can access the properties from the data context as follows:
<Button Text="{Binding ChildVM.SomeProperty}"/>
But it becomes very repetitive. I would like to be able to:
<Button Text="{Binding SomeProperty}"/>
Something like this pseudo is installed in my datacontext:
DataContext="{StaticResource MainViewModel, Path=ParentVM.ChildVM}"
Any ideas?
source
share