Windows 8 Data Binding Bug - OnPropertyChanged Updates Wrong Object
- by Andrew
I'm experiencing some really weird behavior with data binding in Windows 8. I have a combobox set up like this:
<ComboBox VerticalAlignment="Center" Margin="0,18,0,0" HorizontalAlignment="Right" Height="Auto" Width="138" Background="{StaticResource DarkBackgroundBrush}" BorderThickness="0"
ItemsSource="{Binding CurrentForum.SortValues}" SelectedItem="{Binding CurrentForum.CurrentSort, Mode=TwoWay}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Right" Text="{Binding Converter={StaticResource SortValueConverter}}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Inside of a page with the DataContext set to a statically located ViewModel. When I change that ViewModel's CurrentForm attribute, who's property is implemented like this...
public FormViewModel CurrentForm
{
get
{
return _currentForm;
}
set
{
_currentForm = value;
if (!_currentForm.IsLoaded)
{
_currentSubreddit.Refresh.Execute(null);
}
RaisePropertyChanged("CurrentForm");
}
}
... something really strange happens. The previous FormViewModel's CurrentSort property is changed to the new FormViewModel's current sort property. This happens as the RaisePropertyChanged event is called, through a managed-to-native transition, with native code invoking the setter of CurrentSort of the previous FormViewModel.
Does that sound like a bug in Win8's data binding? Am I doing something wrong?