【问题标题】:Xamarin Forms Search Bar with PickerXamarin 表单搜索栏与选择器
【发布时间】:2018-05-14 17:00:24
【问题描述】:

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

【问题讨论】:

    标签: xamarin xamarin.forms


    【解决方案1】:

    您可以查看使用 Xamarin 表单的 XFX 控件。

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

    在页面顶部添加一个命名空间引用:

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

    那么你使用控件如下:

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

    此控件允许绑定到项目源和选定的项目

    【讨论】:

      【解决方案2】:

      当您在元素上调用 Focus() 时会显示选取器对话框,因此您可以放置​​一个隐藏的选取器并从 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();
                  }
              }
      }
      

      【讨论】:

        猜你喜欢
        • 2017-11-12
        • 2018-10-14
        • 1970-01-01
        • 2020-03-17
        • 1970-01-01
        • 1970-01-01
        • 2018-04-04
        • 1970-01-01
        • 2018-02-02
        相关资源
        最近更新 更多