首页 文章

Xamarin使用Picker构建搜索栏

提问于
浏览
0

我有一个xamarin表单应用程序,我想使用搜索栏控件,焦点将拉出一个选择器 . 无论如何我可以扩展搜索栏以提供此功能吗?换句话说,我不希望用户在搜索栏框中输入文本,而是从选择列表中选择它 . 任何例子将不胜感激 .

1 回答

  • 0

    在元素上调用Focus()时会显示Picker对话框,因此您可以放置一个隐藏的Picker并从ToolbarItem的Click Handler调用该方法 .

    <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();
                }
            }
    }
    

相关问题