Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding to ExpandoObject. PropertyChanged not working

In my Windows Store app I have a list populated with ExpandoObjects. Data binding works fine for the initial values, but not for an image property I set asyncronously after a file has been downloaded:

public static async void Set<T>(this ExpandoObject thisObject, string property, Func<Task<T>> setter) {
        var expando = thisObject as IDictionary<string, Object>;

        if (!expando.ContainsKey(property)) {
            expando.Add(property, null);
        }
        expando[property] = await setter.Invoke();
    }

Hooking up to the PropertyChanged event on the ExpandoObject confirms that it is fired for all objects. The new property is attached to the object and the value is correct, but the items in the ListView are not updated in full.

The list contains 14 objects. If I use regular typed objects instead of ExpandoObjects and use the same async setting of the image property, some of the 14 objects gets updated in the view (the ones not currently visible). If I implement INotifyPropertyChanged in the class all 14 gets updated. Using ExpandoObjects I get the exact behaviour as with the typed objects without INPC: items not currently visible are updated.

So it seems that PropertyChanged is not working with ExpandoObject and data binding.

It workds as intended in WPF, but not in a Store App. See comparison: https://sites.google.com/site/moramatte/ExpandoComparison.zip?attredirects=0&d=1

like image 330
user958578 Avatar asked Nov 29 '12 07:11

user958578


1 Answers

They didn't add a default mechanism for binding to dynamic objects and instead added a new interface ICustomTypeProvider. And that interface wasn't added to an ExpandoObject either, but with expando you should be able to use the indexer binding since it is an IDictionary<string, object> that implements INotifyPropertyChanged.

<TextBlock Text="{Binding [Foo]}"/>
like image 98
Roster Neo Avatar answered Oct 15 '22 20:10

Roster Neo