简体   繁体   中英

Xamarin.Forms ListView Approach

I am creating a Xamarin.Forms application and have run into an issue as I plan the UI. I have a form that I need to display a value which can be one of several (over 80 choices). 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. 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> .......

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.

Ideally, the UI would look like an Entry control and would open up the selection page once the user taps the Entry control. 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.

Unfortunately, an Entry object does not have a 'focussed' event or similar. However, this can be easily achieved through creating a custom Entry subclass and writing a customer Renderer for it. 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).

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.
I have implemented this by using Buttons (select xx) and then show a PopUp-Control (from XLabs). With the PopUp-Control, you don't need to call further pages, what will make easier the whole logic:-). On the PopUp, I the show an entry and a 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. This works fine, even with 4'000 List-entry's.
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. 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...

You can find more information's to the PopUp-control here:

How to use the PopUp-Control

Hope this helps...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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