使用ContentPresenter MVVM Xamarin Forms导航



所以我试图在Xamarin表单中使用MVVM进行简单的导航,人们建议我将控件模板与内容演示器一起使用。到目前为止还不错。

我制作了控制模板,但我不知道如何将内容演示者绑定到我的按钮,这样当我单击按钮时它就会更改。

应用Xaml

<Application.Resources>
<!-- Application resource dictionary -->
<ResourceDictionary>
<ControlTemplate x:Key="ThemeMaster">
<StackLayout>
<Label Text="App name" BackgroundColor="Blue"></Label>
<ContentPresenter x:Name="ContentPresenter"
Content="{Binding changeContentCommand}">
</ContentPresenter>
<Button Text="Click me" Command="{Binding changeContentButtonCommand}"></Button>
</StackLayout>
</ControlTemplate>

当我打开程序时,contentpresent开始按原样显示mainPage,但我应该在MainViewModel.cs中写些什么?也更改contentpresent,比如LeaderBoardPage?

我认为您应该为不同的内容创建不同的ControlTemplate

最新更新