Topic Author
Posts: 47
Joined: 04 Dec 2014, 14:47

PropertyChanged in Thread not working properly

18 Dec 2015, 18:58

Hi, after upgrading to 1.2.5f8 (the same with 1.2.5f9) I have problems with PropertyChanged in a ViewModel that I use for template within a ListBox.

As I am receiving data asynchronously and then assigning to a property of the view model (launching the NotifyPropertyChanged) it should have refreshed it in the view, but this is not happening always, just randomly.
<ListBox x:Name="LvOrders" SelectedItem="{Binding SelectedOrder}" ItemsSource="{Binding Orders}">
                  <DataTemplate DataType="{x:Type local:TrackedOrderViewModel}"><Grid Grid.Row="1" Orientation="Vertical" HorizontalAlignment="Left" Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualWidth}">
                        <TextBlock Text="{Binding WholeAddress}" FontSize="{Binding FontSize}" Foreground="{Binding Foreground}" Margin="{Binding MarginSize}" HorizontalAlignment="Left" TextWrapping="Wrap" />
public class TrackedOrderViewModel : ViewModelBaseUnity
        private Address OrderAddressTo
            get { return _addressTo; }
                _addressTo = value;
                City = _addressTo.City;
                Street = _addressTo.Street;

        public TrackedOrder Order
            get { return _order; }
                _order = value;
                _order.AddressTo.OnLoadedAction = o =>
                    OrderAddressTo = o as Address;

        public string WholeAddress
                return string.Format("{0}. {1}", City, Street); 


As you can see in the assign of the order, the OnLoadedAction is an action that would be called within a Thread, and so it is, but the PropertyChanged event don't update the view always (it is random).

do you have any idea why? I think to have seen in Trello that something was refactored about this, so maybe you can quickly figure out... Other wise I'll try to provide more information.

User avatar
Site Admin
Posts: 2064
Joined: 22 Dec 2011, 19:20

Re: PropertyChanged in Thread not working properly

19 Dec 2015, 11:51


Updating the UI tree from a thread is not supported. It may work sometimes when main thread is not accessing the data at the same time, but you shouldn't notify of property changes (that might produce modifications to UI elements) in a separate thread.

Maybe is a good idea to have an INotifyPropertyChanged base class that deals with thread access, something similar to what is explained in this article:

Anyway, we should add some kind of check when UI is accessed from different threads. I will add this task to our trello board.

Let me know if you need more help.

Who is online

Users browsing this forum: Bing [Bot], sfernandez and 0 guests