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>

我还有两个按钮来更改用户控件:

<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 的视图模型中更改 Content Control 的内容?

4

1 回答 1

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

我希望这将有所帮助。

于 2012-07-14T17:24:46.907 回答