I have the following:
<DataTemplate DataType="{x:Type vm:MyViewModel}">
<Grid>
...
<ContentControl Content="{Binding}"
ContentTemplateSelector="{StaticResource MySelector}"/>
...
</Grid>
</DataTemplate>
where MySelector
gives a different view of the MyViewModel
as indicated by MyViewModel.ViewName
, and
class MyViewModel : INotifyPropertyChanged
{
...
public string ViewName
{
get { return _viewName; }
set
{
_viewName = value;
OnPropertyChanged(() => ViewName);
}
}
...
}
How can I get the binding in the content control to update when ViewName
changes?
NOTE I've also tried creating a property on MyViewModel
that simply returns itself, binding to that, and then raising PropertyChanged
for that property whenever ViewName
changes.
<DataTemplate DataType="{x:Type vm:MyViewModel}">
<Grid>
...
<ContentControl Content="{Binding This}"
ContentTemplateSelector="{StaticResource MySelector}"/>
...
</Grid>
</DataTemplate>
and
class MyViewModel : INotifyPropertyChanged
{
...
public string ViewName
{
get { return _viewName; }
set
{
_viewName = value;
OnPropertyChanged(() => ViewName);
OnPropertyChanged(() => This);
}
}
public MyViewModel This { get { return this; } }
...
}
But my template selector is not invoked when ViewName
changes in either case.