2012-07-13 61 views
1

在主窗口中,我有参照两个用户控件:变化用户控制

<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> 

我还的hve两个按钮来改变用户控制:

<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

是否要在UI上执行任何操作后更改内容或什么? – ethicallogics 2012-07-14 07:16:10

+0

我想要在其中一个按钮点击事件(命令)上更改内容。 – netmajor 2012-07-14 13:13:48

回答

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; 
     } 
    } 

我希望这会有所帮助。