I’m working on a C# Metro style app for Windows 8, and I’m having a problem getting my data bound combo box to update when the source data changes.
Here’s the data source:
public class Range
{
public string range_name { get; set; }
public string range_description { get; set; }
public int min { get; set; }
public int max { get; set; }
}
static List<Range> ranges = new List<Range>
{
new Range { range_name = "Foo", range_description = "Foo: (0-10)", min = 0, max = 10},
new Range { range_name = "Bar", range_description = "Bar: (5-15)", min = 5, max = 15},
new Range { range_name = "Baz", range_description = "Baz: (10-20)", min = 10, max = 20},
new Range { range_name = "Custom", range_description = "Custom: (0-20)", min = 0, max = 20}
};
And the combo box:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<ComboBox Name="combo_range" ItemsSource="{Binding Path=Range}" DisplayMemberPath="range_description" SelectedValuePath="range_name" SelectedValue="{Binding Path=Range}" SelectionChanged="combo_range_SelectionChanged"/>
</Grid>
The user can manipulate the min/max range range of the ‘custom’ range in the app, but the combo box only updates when I change away from that record and then change back to ‘custom’.
What do I need to do to force the combo box to update in real time when the source data changes?
Thanks
Try implementing INotifyPropertyChanged in your Range class:
Hope it helps 😉