【发布时间】:2017-11-02 09:45:09
【问题描述】:
我是 MVVM 模式的新手,但我了解其中一些。我目前遇到的问题是我想在按下按钮时打开一个页面,使用 MVVM 模式。当按下六个按钮之一时,一个命令可以给我按下的按钮的名称。我的问题是我不知道按下按钮时如何设置框架的内容。
<StackPanel>
<Button Content="Page 1" x:Name="Page1"
Command="{Binding SimpleCommand, Source={StaticResource ViewModelBase}}"
CommandParameter="{Binding Name, ElementName=Page1}"/>
<Button Content="Page 2" x:Name="Page2"
Command="{Binding SimpleCommand, Source={StaticResource ViewModelBase}}"
CommandParameter="{Binding Name, ElementName=Page2}"/>
</StackPanel>
上面是现在的 XAML 代码。简单的命令就是在按钮上写出名字
<Frame x:Name="MainFrame" Grid.Column="1" Grid.Row="1"
Content="{Binding Name, Converter={StaticResource Converter}, ElementName=Page1}"
NavigationUIVisibility="Hidden"/>
上面是我要更改内容的框架。在编译时我可以设置它应该打开的页面。我想在运行时设置内容,我使用按钮名称。 转换器只是 IValueConverter,我在其中设置它应该显示的页面。
【问题讨论】:
-
嗨,欢迎来到 SO。请添加您的代码。
-
嘿。现在添加代码。我希望它会有所帮助。