使用ContentPresenter MVVM Xamarin表单导航

时间:2018-12-10 22:11:49

标签: c# mvvm xamarin.forms

因此,我试图使用Xamarin形式的MVVM进行简单导航,人们建议我将控件模板与内容演示者一起使用。 到目前为止一切顺利。

我制作了控件模板,但是我不确定如何将内容呈现器绑定到我的按钮,因此单击它们时按钮会更改。

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

当我打开程序时,contentpresenter开始按原样显示mainPage,但是我应该在MainViewModel.cs中写什么,也要更改contentpresenter,也可以说LeaderBoardPage?

1 个答案:

答案 0 :(得分:0)

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