How to add search bar in navigation bar of tabbed page - xamarin.forms

I am using the xamarin. forms application, where there will be two tabs with a search icon in the navigation bar. What I wanted here to implement is, when the search icon is tapped all the navigation bar and the tabs should disappear and open the search bar with respect to the current tab.
The example: initially, the page will be like as
when the search icon is tapped, I want the view as follows.
how can it be achieved?

You can use Xamarin's latest Xamarin.Forms Shell to achieve tabbed page kind of Layout.
Refer to following code structure:
AppShell.Xaml
<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:ProjectName.Views"
x:Class="ProjectName.AppShell">
<Tab>
<ShellContent
Title="Page1"
ContentTemplate="{DataTemplate views:Page1}" />
<ShellContent
Title="Page2"
ContentTemplate="{DataTemplate views:Page2}" />
</Tab>
</Shell>
Page1.Xaml
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ProjectName.Views.Page1"
Title="Page1">
<Shell.SearchHandler>
<SearchHandler Placeholder="Enter search term"/>
</Shell.SearchHandler>
<ContentPage.Content>
<!--Get you desired content here-->
</ContentPage.Content>
</ContentPage>
Output:

Related

Xamarin Forms Flyout Page not showing in iOS

I'm using xamarin forms flyout page to make the settings page, it works fine like the image below but it does not show in iOS. This setting page is not the root page
Android:
iOs:
My flyout page is just a normal flyout out page was created from visual studio.
Flyout page:
app shell:
I don't know what happened, anyone has any idea?
It is not recommend to use FlyoutPage inside shell, you can post an issue in github if you insist. However, you can use TabbedPage and FlyoutPage together instead.
like:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:My_Forms_Test2.Views"
x:Class="My_Forms_Test2.MainTabbedPage">
<NavigationPage Title="Settings" >
<x:Arguments>
<local:Page1/>
</x:Arguments>
</NavigationPage>
<local:Page2/>
<local:Page3/>
flyoutpage:
<FlyoutPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:My_Forms_Test2.Views"
x:Class="My_Forms_Test2.Views.Page1"
Title="Settings">
<FlyoutPage.Flyout>
<local:MenuPage/>
</FlyoutPage.Flyout>
<FlyoutPage.Detail>
<local:Page2/>
</FlyoutPage.Detail>
</FlyoutPage>
Here is the result:

How to disable a ShellContent button

I have a brand new Xamarin Shell application. I just want to disable one of the buttons in the TabBar section. I see there is an IsEnabled property but even if I set it to False, the button is still clickable and the view becomes visible.
<TabBar>
<ShellContent Title="Home" Route="HomePage" ContentTemplate="{DataTemplate local:HomePage}"/>
<ShellContent Title="Settings" Route="SettingsPage" ContentTemplate="{DataTemplate local:SettingsPage}" IsEnabled="False" />
</TabBar>
Is it not possible to disable the buttons that appear in the lower navigation of a Xamarin.Forms application? I was hoping to disable certain buttons when conditions weren't met and enable them using event listeners.
I believe #ToolmakerSteve's comments would work, what I ended up doing was putting each ShellContent in its own Tab:
<TabBar>
<Tab>
<ShellContent Title="Home" Route="HomePage" ConentTemplate="{DataTemplate local:HomePage}"/>
</Tab>
<Tab>
<ShellContent Title="Settings" Route="SettingsPage" ContentTemplate="{Data Template local:SettingsPage}" IsEnabled="False" />
</Tab>
</TabBar>
Then I subscribed to events in the ShellContent class and enabled / disabled the Settings button at will.

Is there a way to hide the TOP tab bar?

I am using Xamarin.Forms Shell and I have bottom Tab Bar navigation with no Flyout.
<TabBar Route="tabs">
<Tab Title="Page1" Route="page1" Icon="page1.png">
<ShellContent ContentTemplate="{DataTemplate local:Page1}" />
</Tab>
<Tab Title="Page2" Route="page2" Icon="page2.png">
<ShellContent Route="page2A" ContentTemplate="{DataTemplate local:Page2A}" />
<ShellContent Route="page2B" ContentTemplate="{DataTemplate local:Page2B}" />
</Tab>
<Tab Title="Page3" Route="page3" Icon="page3.png">
<ShellContent ContentTemplate="{DataTemplate local:Page3}" />
</Tab>
</TabBar>
I want the content of the page2 tab to be programatically determined using GoToAsync("tabs/page2/page2A") and GoToAsync("tabs/page2/page2B").
This way there should be persistence when the user navigates between tabs as to which ShellContent is displayed (e.g. page2A or page2B).
The behaviour works fine, but I want to hide the TOP Tab Bar that allows the user to navigate between the two ShellContent pages. Is there a way to do that in Xamarin.Forms Shell?
I can't find a way to do this with routes. The desired behaviour can be achieved with:
(Shell).CurrentItem.Navigation.PushAsync({desired_content});
By pushing onto the CurrentItem's Navigation the content within a tab can be updated, and will persist while the user navigates between bottom-bar tabs.

How can I use partial views in Prism?

I have Prism 7.1 with Xamarin Forms 3.5. I can't get partial views to work correctly.
The consuming view has this up the top
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
xmlns:converters="clr-namespace:MapManPrism.Converters"
x:Class="MapManPrism.Views.WelcomeWizardPage"
xmlns:mvvm="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
x:Name="wizard"
Title="Welcome" xmlns:cv="clr-namespace:PanCardView;assembly=PanCardView"
xmlns:cvi="clr-namespace:PanCardView.Controls;assembly=PanCardView" xmlns:views="clr-namespace:MapManPrism.Views">
As you can see I am giving the consuming page a name (wizard).
I then have a carouselview that has several views in it
<cv:CarouselView SelectedIndex="{Binding CurrentPage}" IsPanSwipeEnabled="false" IsUserInteractionEnabled="false">
<cv:CarouselView.ItemsSource>
<x:Array Type="{x:Type View}">
<ContentView Padding="10" Margin="10">
...
</ContentView>
<ContentView>
<Frame>
<views:PublisherDetails mvvm:ViewModelLocator.AutowirePartialView="{x:Reference wizard}"></views:PublisherDetails>
</Frame>
</ContentView>
In my app.xaml.cs I have this line
ViewModelLocationProvider.Register<PublisherDetails, PublisherDetailsViewModel>();
But I can't navigate to the consuming page when its set up like this. Removing "mvvm:ViewModelLocator.AutowirePartialView="{x:Reference wizard}"" makes it work, but obviously the view model for the partial view doesn't get wired up.
How can I fix this? Or, is there a way to manually connect the partial view's view model to see if that fixes it?

SlideOverKit Menu as hamburger menu using FreshMVVM

I am new in Xamarin and learning FreshMVVM.
Please can anyone guide me how can I dispaly SlideOverKit: Right Menu as hamburger menu instead on button click using FreshMVVM for MasterDetail form.
Thanks in advance.
I am not sure abut FreshMVVM but all you have to do is to add a ToolbarItem which has an icon of Menu. Than, bind the click command to show the slideOverKit menu.
<ContentPage>
<ContentPage.ToolbarItems>
<ToolbarItem Name="Cart" Command="{Binding GoToCartCommand}" Icon="Icons/cart.png"></ToolbarItem>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<!-- your content goes here -->
</ContentPage.Content>
</ContentPage>

Resources