Windows 8 Data Binding Bug - OnPropertyChanged Updates Wrong Object

Posted by Andrew on Stack Overflow See other posts from Stack Overflow or by Andrew
Published on 2012-11-18T16:57:18Z Indexed on 2012/11/18 16:59 UTC
Read the original article Hit count: 257

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about Windows

Related posts about data-binding