Scott
Scott

Reputation: 153

Xamarin Forms Search Bar with Picker

I have a xamarin forms app and I would like to use the search bar control that upon focus will pull up a picker. Is there anyway I can extend the search bar to provide this functionality? In other words I don’t want the user to enter text in the search bar box, rather it’s selected from the pick list. Any examples would be appreciated.

Upvotes: 0

Views: 6787

Answers (2)

TResponse
TResponse

Reputation: 4125

You can look at using the XFX Controls for Xamarin Forms.

https://github.com/XamFormsExtended/Xfx.Controls

In the top of your page add a namespace reference to :

xmlns:xfx="clr-namespace:Xfx;assembly=Xfx.Controls"

Then you use the control as follows:

<!-- XfxComboBox-->
<xfx:XfxComboBox                
             Placeholder="Select make"
             SelectedItem="{Binding SelectedVehicleMake}"
             Text="{Binding Description}"
             ItemsSource="{Binding AssetMakes}"/>       

This control allows to bind to a item source and a selected Item

Upvotes: 2

Daniel Skrzeszowski
Daniel Skrzeszowski

Reputation: 31

Picker dialog is shown when you call Focus() on the element, so you could just place a hidden Picker and call the method from the Click Handler of the ToolbarItem.

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
                 x:Class="MyApp.Views.MyPage" 
                 Title="My Page Title" 
                 x:Name="MyPage">
        <ContentPage.ToolbarItems>
            <ToolbarItem Text="ShowPicker" Clicked="ShowPicker">
            </ToolbarItem>
        </ContentPage.ToolbarItems>
        <ContentPage.Content>
            <DatePicker x:Name="MyPicker" IsVisible="false" />
        </ContentPage.Content>
    </ContentPage>



namespace MyApp.Views
{
    public partial class MyPage : ContentPage
        {    
            public ItemsPage()
            {
                InitializeComponent();    
            }

            void ShowPicker(object sender, EventArgs e)
            {
                MyPicker.Focus();
            }
        }
}

Upvotes: 0

Related Questions