PropertyChanged in Thread not working properly
Posted: 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.
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.
regards
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.
Code: Select all
<ListBox x:Name="LvOrders" SelectedItem="{Binding SelectedOrder}" ItemsSource="{Binding Orders}">
<ListBox.Resources>
<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" />
</Grid>
</DataTemplate>
</ListBox.Resources>
</ListBox>
Code: Select all
public class TrackedOrderViewModel : ViewModelBaseUnity
{
private Address OrderAddressTo
{
get { return _addressTo; }
set
{
_addressTo = value;
City = _addressTo.City;
Street = _addressTo.Street;
NotifyPropertyChanged("WholeAddress");
}
}
public TrackedOrder Order
{
get { return _order; }
set
{
_order = value;
_order.AddressTo.OnLoadedAction = o =>
{
OrderAddressTo = o as Address;
};
}
}
public string WholeAddress
{
get
{
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.
regards