FlyoutPage on Xamarin formx 5.0 - xamarin.forms

Om Xamarin Forms we use this code to create Master Page:
<MasterDetailPage.ToolbarItems>
<ToolbarItem Priority="0" Order="Secondary" Text="{x:DynamicResource MasterPageControls}" Command="{Binding ControlsCommand}" />
<ToolbarItem Priority="1" Order="Secondary" Text="{x:DynamicResource Refresh}" Command="{Binding RefreshCommand}" />
<ToolbarItem Priority="2" Order="Secondary" Text="{x:DynamicResource About}" Command="{Binding AboutCommand}" />
<ToolbarItem Priority="4" Order="Secondary" Text="{x:DynamicResource Logout}" Command="{Binding LogoutCommand}"/>
</MasterDetailPage.ToolbarItems>
<MasterDetailPage.Master>
<NavigationPage Title="Title" IconImageSource="hamburger.png">
<x:Arguments>
<ContentPage Title="Menu"
BackgroundColor="White"
NavigationPage.HasNavigationBar="False">
....
</ContentPage>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Master>
Now i migrate my code to version 5.0 and i change it like this (from this link):
<FlyoutPage.ToolbarItems>
<ToolbarItem Priority="0" Order="Secondary" Text="{x:DynamicResource MasterPageControls}" />
<ToolbarItem Priority="1" Order="Secondary" Text="{x:DynamicResource Refresh}" />
<ToolbarItem Priority="2" Order="Secondary" Text="{x:DynamicResource About}" />
<ToolbarItem Priority="4" Order="Secondary" Text="{x:DynamicResource Logout}"/>
</FlyoutPage.ToolbarItems>
<FlyoutPage.Flyout>
<NavigationPage Title="Title" IconImageSource="hamburger.png">
<x:Arguments>
<ContentPage Title="Menu"
BackgroundColor="White"
NavigationPage.HasNavigationBar="False">
...
</ContentPage>
</x:Arguments>
</NavigationPage>
</FlyoutPage.Flyout>
Register:
containerRegistry.RegisterForNavigation<NavigationPage>("NavigationPage");
containerRegistry.RegisterForNavigation<PrismMasterDetailPage, PrismMasterDetailPageViewModel>("MasterPage");
containerRegistry.RegisterForNavigation<MainPage, MainPageViewModel>();
And navigation:
await NavigationService.NavigateAsync("/MasterPage/NavigationPage/MainPage");
When i try run application i got this exception:
Flyout and Detail must be set before using a FlyoutPage
What should i change in my code to work it correctly (it should show on right side MasterPage and on center of the screen MainPage) ?
EDIT:
I change my code by adding a login page. It run on App.xaml.cs likt this:
await NavigationService.NavigateAsync($"/NavigationPage/{nameof(LoginPage)}");
On LoginPageViewModel i have binded command to button where i run a method to navigate to MainPage. In Xamarin.Forms 4.8 we use that command:
await NavigationService.NavigateAsync("/MasterPage/NavigationPage/MainPage",
new NavigationParameters {{nameof(LoginPageViewModel), string.Empty}});
But now when i use it Navigation didn't work (not have any exception or somethink like that):(
When i remove /MasterPage from name i'm navigate to MainPage but i not have my MasterPage
Edit 2:
I change code form use FlyoutPage to MasterDetailPage and it start work, but MasterDetailPage is obsolete in xamarin forms 5

FlyoutPage is not supported by Prism 8. You can read more about it here and here.

AS the error shows Flyout and Detail must be set before using a FlyoutPage .
Try to set FlyoutPage.Detail as well in FlyoutPage xaml .
<FlyoutPage.Flyout>
<NavigationPage Title="Title" IconImageSource="hamburger.png">
<x:Arguments>
<ContentPage Title="Menu"
BackgroundColor="White"
NavigationPage.HasNavigationBar="False">
...
</ContentPage>
</x:Arguments>
</NavigationPage>
</FlyoutPage.Flyout>
<FlyoutPage.Detail>
<NavigationPage>
<x:Arguments>
<pages:FlyoutPage1Detail />
</x:Arguments>
</NavigationPage>
</FlyoutPage.Detail>
Refr to https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/flyoutpage#create-a-flyoutpage.

Actually Prism 8 didn't support FlyoutPage, so when i back to:
<MasterDetailPage.ToolbarItems>
<ToolbarItem Priority="0" Order="Secondary" Text="{x:DynamicResource MasterPageControls}" Command="{Binding ControlsCommand}" />
<ToolbarItem Priority="1" Order="Secondary" Text="{x:DynamicResource Refresh}" Command="{Binding RefreshCommand}" />
<ToolbarItem Priority="2" Order="Secondary" Text="{x:DynamicResource About}" Command="{Binding AboutCommand}" />
<ToolbarItem Priority="4" Order="Secondary" Text="{x:DynamicResource Logout}" Command="{Binding LogoutCommand}"/>
</MasterDetailPage.ToolbarItems>
<MasterDetailPage.Master>
<NavigationPage Title="Title" IconImageSource="hamburger.png">
<x:Arguments>
<ContentPage Title="Menu"
BackgroundColor="White"
NavigationPage.HasNavigationBar="False">
....
</ContentPage>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Master>
It start work, but i have warning becouse MasterDetailPage is obsolete but work :) I need to wait for Prism 8.1 and migrate MasterDetailPage to FlyoutPage

Related

Xamarin Forms Tabbed structure - show same button at bottom of all tabs

My xamarin forms application is based on the tabbed structure. What I want to achieve is as follows: I want to show a button at the bottom of all tabbed pages, it should be the same button. When I navigate to other tab, the same button should appear with same logic behind it. How can I achieve this?
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:views="clr-namespace:DriverApp.Views"
xmlns:vm="clr-namespace:DriverApp.ViewModels"
x:Class="DriverApp.Views.PlanningDetailPage">
<TabbedPage.Children>
<NavigationPage Title="Activity">
<x:Arguments>
<views:ActivityPage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Vehicle">
<x:Arguments>
<views:VehiclePage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Driver">
<x:Arguments>
<views:DriverPage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Checklist">
<x:Arguments>
<views:CheckListPage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Attachment">
<x:Arguments>
<views:AttachmentPage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Damage">
<x:Arguments>
<views:DamagePage />
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>

Xamarin.Forms ToolbarItems Title

Is it possible to to disable title of current page in toolbarItems?
https://imgur.com/a/MsX0FKp
<ToolbarItem Text="{Binding positionNumber}"
/>
<ToolbarItem Text="PREV"
Clicked="previousQuestion"/>
<ToolbarItem Text="HINT"
/>
<ToolbarItem Text="NEXT"
Clicked="nextQuestion"/>
</ContentPage.ToolbarItems>
I've achieved it by simply adding
ToolbarItem Text=" 'space' PREV"
is there a proper way to do this?

How do I set the icon property in Prism for a TabbedPage in Prism for Xamarin Forms?

I'm extending the prism sample here to also include icons, and some additional navigation. My goal is to add something like the code below (where the icon information is) and am unsure how to add that to either my view, or the view model correctly.
<?xml version="1.0" encoding="UTF-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:WebOfTrust.Views"
x:Class="WebOfTrust.Views.Client.WebOfTrustMainPage"
Title="{Binding Title}">
<TabbedPage.Children>
<!-- HOW DO I SET AN ICON FOR THESE? Either in the View or Model? -->
<NavigationPage Title="Contacts" >
<x:Arguments>
<local:Client.MyPeople.MyPeopleList/>
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Places" Icon="Image7DoesntWork.png">
<x:Arguments>
<local:Client.MyPlaces.MyPlacesList/>
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Docs" Icon="Image7DoesntWork.png">
<x:Arguments>
<local:Client.MyWallet.WalletCards/>
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>
What normally works
I normally have a navigation page in the view where I specify the icon below.
<NavigationPage Title="Trust Anchor List">
<NavigationPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<On Platform="iOS" Value="tab_feed.png"/>
</OnPlatform>
</NavigationPage.Icon>
<x:Arguments>
<local:Client.TrustAnchorList />
</x:Arguments>
</NavigationPage>
Question
What is the right way to set an icon in either the view or the model when using Prism?
just add the icon attribute in the children of the tabbed page.
It works fine for me
<local:ContactUs Icon="Icons/History_Tab.png" Title="{Translate:TranslateExtension Text=NewMessage}" />
my icons are under a folder in the resources but you can put them anywhere.

how to set icon for Toolbar Item in Xamarin forms

My xamarin andorid project does not have Drawawble folders under Resources, I have mipmap folders instead. I'm trying to set icon for a toolbar item in shared project. If I set an image as embeded resource I should be able to access it from the shared project, am I wrong?
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="BoringAppUi.MainPage" Title="Main Page">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Logout" Clicked="OnLogoutButtonClicked" Order="Primary" Priority="0"/>
<ToolbarItem Text="Home" Icon="#mipmap/baseline_home_blue_48.png" Clicked="OnHomeIconClicked" Order="Primary" Priority="1"/>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<StackLayout>
<Label Text="Main app content goes here" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
Also I've tried setting it from the code behind
var toolbarItemHome = new ToolbarItem
{
Text = "Home",
Icon = "#mipmap/baseline_home_blue_48.png"
};
toolbarItemHome.Clicked += OnHomeIconClicked;
ToolbarItems.Add(toolbarItemHome);
From c# code:
new ToolbarItem () { Icon = "icon.png"}
Or from xaml:
<ToolbarItem Name="iconexample" Icon="icon.png" Priority="0" Order="Primary" Activated="Onclick" />
Have that in mind:
iOS - place the image at /mipmap/icon.png
Android - place the image at /mipmap/drawable/icon.png

How to add a menu to a Xamarin.Forms ToolbarItem?

I am looking for a way to add a menu to my ToolbarItem. Right now its just clickable text, here is an example of what I am trying to create,
Here is what I have so far:
<ContentPage.ToolbarItems>
<ToolbarItem Text="{Binding EditButtonText, Mode=TwoWay}" Clicked="EditClicked" />
</ContentPage.ToolbarItems>
You should be able to set the order of the ToolBarItem to Secondary to force the option into an overflow menu on Android:
<ContentPage.ToolbarItems>
<ToolbarItem Text="{Binding EditButtonText, Mode=TwoWay}" Clicked="EditClicked" Order="Secondary" />
</ContentPage.ToolbarItems>

Resources