简体   繁体   English

Xamarin.Forms ListView方法

[英]Xamarin.Forms ListView Approach

I am creating a Xamarin.Forms application and have run into an issue as I plan the UI. 我正在创建Xamarin.Forms应用程序,并且在规划UI时遇到问题。 I have a form that I need to display a value which can be one of several (over 80 choices). 我有一个表格需要显示一个值,该值可以是多个值(超过80个选择)之一。 A ListView on the Form is not practical as the user must be able to select from several top level groupings to get to an actual selectable item. 窗体上的ListView不切实际,因为用户必须能够从几个顶级分组中进行选择才能获得实际的可选项目。 For example: 例如:

Category 1> Sub Category 1-1> Option 1... Option 12 Sub Category 1-2> Option 13... Option 20 Category 2> Sub Category 2-1> Option 21... Option 35 Sub Category 2-2> Option 36... Option 50 Category N> Sub Category N-1> ....... Sub Category NX> ....... 类别1>子类别1-1>选项1 ...选项12子类别1-2>选项13 ...选项20类别2>子类别2-1>选项21 ...选项35子类别2-2 >选项36 ...选项50类别N>子类别N-1> .......子类别NX> .......

I have a page that lists each of the Categories, then (once selected) each of the Sub Categories, then ultimately the options. 我有一个页面,列出每个类别,然后(一旦选中)每个子类别,最后列出选项。

My question is: In this scenario, what is the best approach to displaying the blank form (I tried an Entry control, but can't find a way to navigate to the selection page by clicking on it) and then the selected value in the form. 我的问题是:在这种情况下,显示空白表单的最佳方法是什么(我尝试了一个Entry控件,但是找不到通过单击它导航到选择页面的方法),然后在形成。

Ideally, the UI would look like an Entry control and would open up the selection page once the user taps the Entry control. 理想情况下,UI看起来像一个Entry控件,并且一旦用户点击Entry控件便会打开选择页面。 This seems like a fairly simple (and probably common) approach, so I feel like I must be missing something basic. 这似乎是一种非常简单(并且可能很常见)的方法,所以我觉得我必须缺少一些基本知识。

Thanks in advance! 提前致谢!

我将使用“按钮”和“标签”,在其中点击按钮将启动带有选择ListView的模态,完成选择后,值将显示在“标签”中。

A Button in Xamarin.Forms does give you the Clicked event or the bindable Command property that can be bound to the ViewModel to handle the logic. Xamarin.Forms中的Button确实为您提供了Clicked事件或可绑定的Command属性,可以将其绑定到ViewModel来处理逻辑。

Unfortunately, an Entry object does not have a 'focussed' event or similar. 不幸的是,Entry对象没有“聚焦”事件或类似事件。 However, this can be easily achieved through creating a custom Entry subclass and writing a customer Renderer for it. 但是,这可以通过创建自定义Entry子类并为其编写客户渲染器来轻松实现。 This would allow you to create a Focussed bindable property for use (see http://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/ for examples and tips). 这将允许您创建一个Focussed可绑定属性以供使用(有关示例和提示,请参见http://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/ )。

In my app, I have a huge search-page with various ListViews, where the user can select one Item (out of until 4'000) or multiple items. 在我的应用程序中,我有一个巨大的搜索页面,其中包含各种ListView,用户可以在其中选择一个项目(直到4000个)或多个项目。
I have implemented this by using Buttons (select xx) and then show a PopUp-Control (from XLabs). 我已经通过使用Buttons(选择xx)实现了这一点,然后显示了一个PopUp-Control(来自XLabs)。 With the PopUp-Control, you don't need to call further pages, what will make easier the whole logic:-). 使用PopUp-Control,您无需调用其他页面,这将使整个逻辑更容易:-)。 On the PopUp, I the show an entry and a ListView. 在弹出窗口上,我显示一个条目和一个ListView。
As soon as the user types text in the entry, the List (Datasource to the ListView) is filtered "on-the-fly" to the typed text. 一旦用户在条目中键入文本,列表(ListView的数据源)就会“即时”过滤到键入的文本。 This works fine, even with 4'000 List-entry's. 即使使用4'000 List-ents,它也可以正常工作。
So.. I would suggest you to solve your problem on this way. 所以..我建议您以这种方式解决您的问题。
Every time a character is added, I create a new list by the typed text and re-assign it to the ListView. 每次添加字符时,我都会通过键入的文本创建一个新列表,并将其重新分配给ListView。 So you can eg put more then one entry on the PopUp and then filter the List for more the one value at the same time or maybe show the categories one after one... 因此,例如,您可以在PopUp上放置一个以上的条目,然后同时在List过滤更多的一个值,或者一一显示一个类别...

You can find more information's to the PopUp-control here: 您可以在此处找到有关PopUp控件的更多信息:

How to use the PopUp-Control 如何使用PopUp-Control

Hope this helps... 希望这可以帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM