NPadrutt NPadrutt - 1 year ago 103
C# Question

SelectedItem not updated

I have a UWP app with a listbox who is bound to a List of Enums to display the different options with a radio button.

What I want, is that when I select an item (for example yearly), that on the SelectedCategory the BudgetPeriod is changed to the enum yearly. What I tried is the following:

My Listbox:

<ListBox Margin="0,0,0,12"
ItemsSource="{Binding BudgetPeriods}"
SelectedItem="{Binding SelectedCategory.BudgetPeriod}">
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<ControlTemplate TargetType="ListBoxItem">
<RadioButton Content="{TemplateBinding Content}" IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSelected}" />

Selected Category Property:
public CategoryViewModel SelectedCategory
get { return selectedCategory; }
selectedCategory = value;

List of enums:

public List<BudgetPeriod> BudgetPeriods => new List<BudgetPeriod>

Unfortunately the Propety in SelectedCategory.BudgetPeriod is always Monthly (The first selection) and is not changing when I select something else.

The project is open source, so you can checkout the whole code aswell:

Links to the relevant classes:
View Model:



View (code Behind):

Android Layout:

Answer Source

You should set the binding in "TwoWay" mode :

  SelectedItem="{Binding SelectedCategory.BudgetPeriod, Mode=TwoWay}">

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download