【问题标题】:How to add entry inside picker popup? Xamarin Forms如何在选择器弹出窗口中添加条目? Xamarin 表单
【发布时间】:2018-11-29 14:42:32
【问题描述】:

我有一个包含一百多个数据的选择器。我想搜索一个特定的项目。如何在选择器弹出窗口中添加条目?可能吗?如果没有,在选择器中搜索数据的最佳替代方法是什么?

【问题讨论】:

  • 您的 Picker 使用的是什么?如果是Rg.Plugins.Popup,您可以在弹出页面设计中定义任何元素。向页面添加一个条目,然后根据他们输入的内容过滤您的 ObservableCollection
  • @TaylorD 只是一个普通的选择器

标签: xamarin xamarin.forms


【解决方案1】:

您想要的可能可以通过自定义渲染器完成,但我个人不知道如何完成......

如果您想在选择器中添加自定义功能,我强烈推荐 Rg.Plugins.Popup。这个包允许用户定义自己的自定义弹出窗口。我将它用于我开发的应用程序中的所有弹出式页面/控件。

GitHub: Rg.Plugins.Popup

使用EntryListView 定义一个PopupPage,您可以提供您想要的功能。

【讨论】:

    【解决方案2】:

    对此没有开箱即用的解决方案。但是可以使用 rg.plugins.popup.(https://github.com/rotorgames/Rg.Plugins.Popup) 来实现带有搜索栏的选择器。 创建一个带有标签和向下箭头的视图。为此提供单击。在该单击事件中调用 rg.popup。

    弹窗设计供参考。

    <?xml version="1.0" encoding="utf-8" ?>
    <pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"  
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
                 x:Class="iVerify.Sample"  
                 xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"  
                 xmlns:animations="clr-namespace:Rg.Plugins.Popup.Animations;assembly=Rg.Plugins.Popup"  
                 BackgroundColor="Transparent" >
    
        <pages:PopupPage.Animation>
            <animations:ScaleAnimation   
                          PositionIn="Center"  
                          PositionOut="Center"  
                          ScaleIn="1.2"  
                          ScaleOut="0.8"  
                          DurationIn="400"            
                          DurationOut="300"  
                          EasingIn="SinOut"  
                          EasingOut="SinIn"  
          HasBackgroundAnimation="False"/>
        </pages:PopupPage.Animation>
        <StackLayout VerticalOptions="Center"  Padding="10" HorizontalOptions="FillAndExpand" Margin="0,20,0,0" >     
         <StackLayout>
             <SearchBar  x:Name="Searchbar" />
          </StackLayout>
          <StackLayout>
            <ListView  x:Name="ListView"  ItemsSource="{Binding}"
            ItemSelected="List_Tapped">
             ListView.ItemTemplate>
    
                 <DataTemplate>
                 <ViewCell>
                 <ViewCell.View>
    
                  // Your controls
    
                 </ViewCell.View>
                 </ViewCell>
                 </DataTemplate>
                 </ListView.ItemTemplate>
               </ListView>
    
          </StackLayout>
    
        </StackLayout>
    
        </StackLayout>
    </pages:PopupPage> 
    

    通过使用 Itemselected 属性,您可以获得点击视图的值。然后将其设置为Mainpage的标签(点击打开弹出窗口的标签)。这可以通过messeging center来实现。 截图示例

    【讨论】:

      【解决方案3】:

      我使用 Telerik 完成了它,尽管它没有在我的主项目中的 Android 上启动,并且下拉菜单在 UWP 上的行为很奇怪 - 对于某些布局星座,它是向上而不是向下。

      Telerik 不是免费的,所以如果你有它,你可以使用:

             <StackLayout Orientation="Horizontal"
                          VerticalOptions="FillAndExpand"
                          HorizontalOptions="FillAndExpand">
                  <telerikInput:RadAutoCompleteView x:Name="autoCompleteView"
                                                    HorizontalOptions="FillAndExpand"
                                                    ShowSuggestionView="True"
                                                    ShowMoreItems="True"
                                                    SuggestMode="Suggest"
                                                    Watermark="Search here..." />
                  <Button Clicked="Button_Clicked"
                                  Text="▼"/>
             </StackLayout>
      

      在后面的代码中

          private void Button_Clicked(object sender, System.EventArgs e)
          {
              autoCompleteView.ShowSuggestions();
          }
      

      【讨论】:

        猜你喜欢
        • 2018-06-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-21
        • 1970-01-01
        • 2011-03-30
        • 1970-01-01
        • 2018-05-18
        相关资源
        最近更新 更多