How to give an "Empty ListView message" when there is no data source

My application has a ListView with a GridLayout. Now I am trying to inject ListView groups into my application. Suppose the data source is usually Group1, Group2, and Group3. I would like to display all 3 groups all the time, regardless of whether there is an element in it or not. When there is no element in the group, I want to display the message "empty group" under the group heading.

I think the default method that WinRT handles is not displaying an empty group, and that makes a lot of sense in many scenarios. For this, I know that, perhaps, I can add a dummy element to the list view when there is no data, but this is a kind of hacking.

So, is there a better way to do this?

+6
source share
1 answer

Just bind the ListView to a collection of Group objects (where Group is the class you define, and Group1, Group2, and Group3 are such Group objects).

In addition to group level properties (for example, Title), the group contains a collection of Item objects.

In a ListView data item, use a different ListView to display the Item items for each group.

Be careful, nesting GridViews will result in nested ScrollViewers. You want to remove ScrollViewer from internal GridViews by changing their control pattern.

-1
source

Source: https://habr.com/ru/post/915213/


All Articles