Hi developers,
the whole day i am stuck on an (for me) difficult point and i hope there is anybody out there who can help me out
I whould like to have a ContentPage where the user can change some items from a longer list. And it is unknown and left to the user, how many items he can select.
Out of my sight I think it is the best to use the Picker control.
- So the user can click on a plus (+) button and a new Picker control appears (insight the ListView)
- The user selects an item from the Picker list
- If desired he can click again on the plus button and select a second item.
And so on ... maybe until up to 10 Items from 10 different Pickers insight the ListView.
How can I access the user seleceted items in my ViewModel ?
My code:
On the ContentPage I create the ListView:
private ScoutViewModel ViewModel
{
get { return BindingContext as ScoutViewModel; }
}
public ScoutPage()
{
Title = App.Localization.GetString("Title_FilterPage");
BindingContext = new ScoutViewModel(Navigation);
var templateScoutActivityCell = new DataTemplate(typeof(ScoutActivityCell));
var listViewActivities = new ListView
{
AnchorX = 0,
AnchorY = 0,
VerticalOptions = LayoutOptions.StartAndExpand,
HorizontalOptions = LayoutOptions.Start,
ItemTemplate = templateScoutActivityCell,
ItemsSource = ViewModel.Activities,
};
Content = new StackLayout
{
Children =
{
listViewActivities
}
};
}
At the ViewCell (ScoutActivityCell);
public void CreateView()
{
var bindablePickerAllActivities = new BindablePicker
{
AnchorY = 0,
AnchorX = 0,
VerticalOptions = LayoutOptions.Start,
HorizontalOptions = LayoutOptions.FillAndExpand,
ItemsSource = from ac in allActivities select ac.Name
};
bindablePickerAllActivities.SelectedIndexChanged += new EventHandler(OnSelectedIndexChanged);
View = new StackLayout
{
Children =
{
bindablePickerAllActivities,
}
};
}