Wpf 在MVVM模型中动态查看命令的加载和绑定
我有一个主窗口:Wpf 在MVVM模型中动态查看命令的加载和绑定,wpf,mvvm,binding,Wpf,Mvvm,Binding,我有一个主窗口: <Window> <Grid> <Grid x:Name="Container"/> <local:bottompanel x:Name="BP"/> </Grid> </Window> 有没有其他更容易接受的方法 我希望底部面板的datacontext是当前加载视图的datacontext。 我该怎么做 如果我现在理解了你,你能做什么 <DataTemplate DataTyp
<Window>
<Grid>
<Grid x:Name="Container"/>
<local:bottompanel x:Name="BP"/>
</Grid>
</Window>
有没有其他更容易接受的方法
我希望底部面板的datacontext是当前加载视图的datacontext。
我该怎么做
如果我现在理解了你,你能做什么
<DataTemplate DataType="{x:Type vm:vm1}">
view one
</DataTemplate>
<DataTemplate DataType="{x:Type vm:vm2}">
view Two
</DataTemplate>
在视图切换逻辑中将CurrentView设置为AppPeriate viewmodel您可以使用datatemplate保存视图并使用datacontext切换视图。
<DataTemplate DataType="{x:Type vm:vm1}">
view one
</DataTemplate>
<DataTemplate DataType="{x:Type vm:vm2}">
view Two
</DataTemplate>
<Window>
<Grid>
<Grid x:Name="Container"/>
<ContentControl Content="{Binding CurrentView}" />
</Grid>
private ViewModelBase currentview;
public ViewModelBase CurrentView
{
get
{
return currentview;
}
set
{
if (currentview != value)
{
currentview = value;
RaisePropertyChanged("CurrentView");
}
}
}