Hello together
I have the problem that the binding which I set for the selecteditem of the picker will not change when the variable behind has changed.
xml of the picker:<Picker ItemsSource="{Binding TeamListe}" SelectedItem="{Binding SelectedItem}" />
The code of the viewmodel
static string _SelectedItem; public string SelectedItem { get { return _SelectedItem; } set { _SelectedItem = value; OnPropertyChanged("SelectedItem"); } }
When I set the value on appearing it works.
But when I ty to change the selecteditem as an example when I clicked on a button it does not work.
Other bindings like the ItemSource of a Listview in the same project do work.
What do I miss?
Thanks for your help.
Regards
@xama12 said:
How do I access the current?
((MainPageViewModel) BindingContext).SelectedItem = "Two";
Answers
@xama12
Make the BindingMode for SelectedItem TwoWay
@JohnHardman
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
Tried it, does not work.
Show the full XAML and C#
Full code:
MainPage.xml
MainPage.cs
MainPageViewModel.cs
BaseviewModel.cs
In your Clicked handler, you are instantiating a new view model instead of setting the SelectedItem of your existing view model.
How do I access the current?
((MainPageViewModel) BindingContext).SelectedItem = "Two";