Search code examples
xamarin.formsuwpmvvmcross

How can I make CommandBar render in Xamarin Forms UWP?


I have a ContentPage (actually an MvxContentPage) with ToolbarItems defined. The Items appear in Android and iOS as expected, but do not appear at all in UWP. I have tried setting SetToolbarPlacement to both Top and Bottom manually, in both the constructor and the OnAppearing method. Thus far, I have not been able to affect any change in the UWP application. Am I doing something wrong? Can Mvx not render the Toolbar?

<mvx:MvxContentPage
    xmlns:mvx="clr-namespace:MvvmCross.Forms.Views;assembly=MvvmCross.Forms"
    x:TypeArguments="viewModels:CategoryListViewModel"
    xmlns:viewModels=""
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="GSP.X.AccuStore.Forms.Views.Site.Profiles.CategoryListView">

    <ContentPage.ToolbarItems>
        <ToolbarItem Text="Areas" Command="{Binding Path=GoToAreasCommand}" />
    </ContentPage.ToolbarItems>

</mvx:MvxContentPage>

Solution

  • The problem is you have not add start page to NavigationPage. I have test with the follow code in the blank Xamrin.Froms app, the ToolbarItem display well in the top of MainPage.

    public App()
    {
        InitializeComponent();
        var nav = new NavigationPage(new MainPage());
        MainPage = nav;
    }