在主窗口中,我引用了两个用户控件:
<Window x:Class="MediaNet.View.MainWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mainVM="clr-namespace:MediaNet.ViewModel.MainWindow"
xmlns:musicV="clr-namespace:MediaNet.View.MusicWindow"
xmlns:videoV="clr-namespace:MediaNet.View.VideoWindow"
Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<mainVM:MainWindowViewModel />
</Window.DataContext>
<Window.Resources>
<musicV:MusicWindow x:Key="musicView" />
<videoV:VideoWindow x:Key="videoView" />
</Window.Resources>
内容控制:
<WrapPanel Width="362">
<ContentControl Content="" />
</WrapPanel>
我还有两个按钮来更改用户控件:
<Button Content="{Binding MenuNameMusic}" Command="{Binding Path=ShowMusicMenuCommand}">
<Button.RenderTransform>
<RotateTransform CenterY="0" CenterX="0" Angle="0" />
</Button.RenderTransform>
</Button>
<Button Content="{Binding MenuNameVideo}" Command="{Binding Path=ShowMusicMenuCommand}">
<Button.RenderTransform>
<RotateTransform CenterY="0" CenterX="0" Angle="0" />
</Button.RenderTransform>
</Button>
如何更改MainWindow视图模型中的内容控制内容?
答案 0 :(得分:1)
<WrapPanel>
<ContentControl Content="{Binding Content}"/>
</WrapPanel>
public string Content
{
get {
return _content;
}
set {
_content = value;
NotifyChange("Content");
}
}
public ICommand ButtonCommand
{
get
{
Content = "your content that you want to bind";
return somecommandObject;
}
}
我希望这会有所帮助。