Reputation: 2955
I want to create ListBox. User can choose multiple item in it (for example to delete items).
How to do/implement this with MvvmCross?
I'm planning create an app for windows phone and WinRT platform and I want to use MvvmCross.
For windows phone I found LongListMultiSelector Control (Windows Phone Toolkit), which supports this feature. But it leads to more code behind in .xaml page. Also it makes cross platform app more complex.
Is there any other cross platform solution for the problem (desirable with help MvvmCross)?
Thanks in advance!
Upvotes: 1
Views: 379
Reputation: 66882
Generally I tackle multiple selection by putting the selection statein the view model for each list item.
For example, suppose I had a list of Apple
s that I wanted to multi-select. To support this, in my ViewModel I would expose a list of ChooseableApple
s - defined like:
public class ChooseableApple : MvxNotifyPropertyChanged
{
public Apple Apple { /* INPC - get,set */ }
public bool IsSelected { /* INPC - get,set */ }
}
This would then allow me to bind within the list item template to IsSelected
for selection state. and to Apple
for properties like Name
, Colour
, etc
This might not work perfectly with 'built-in' SelectedItem
type properties within controls - but these properties tend to make less sense in Touch environments anyway - they are much more suited to keyboard and mouse environments (IMO)
Upvotes: 1