How to give a "Empty ListView Message" when there is no data source
Asked Answered
G

1

6

My application have a ListView with GridLayout. I am now trying to introduce ListView groups into my application. Say, the data source would usually have Group1, Group2 and Group3. I would like to display all 3 groups all the time regardless there is element in it or not. When there is no element in a group, I want to display a "empty group" message under the group title.

I think the default way that WinRT handles it is not to display the empty group and it makes a lot of sense in many scenarios. To do this, I know that I maybe able to add a dummy item to the list view when there is no data, but this is kind of hacky.

So, is there a better way to do this?

Genous answered 8/5, 2012 at 17:31 Comment(0)
M
-1

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

In addition to Group level properties (such as a Title), have a Group contain a collection of Item objects.

In the ListView's datatemplate, use another ListView to show the Item elements for each Group.

Be careful though, the nesting of GridViews will result in nested ScrollViewers. You would want to remove the ScrollViewer from the inner GridViews by changing their control template.

Marj answered 25/5, 2012 at 19:4 Comment(2)
Thanks for the suggestions, but I don't see how this is better than adding a dummy list view item...Genous
Well, because you don't need a dummy item? I am assuming that a dummy item will require rather complex logic to ensure the dummy item is displayed the way you want, and doesn't react to taps and clicks and other events the way a real item would. This approach removes all of that.Marj

© 2022 - 2024 — McMap. All rights reserved.