TileView Bug with MVVM?

3 posts, 0 answers
  1. Brian
    Brian avatar
    73 posts
    Member since:
    Sep 2010

    Posted 04 May 2011 Link to this post

    I am attempting to use a TileView control to show some items that are returned/loaded via async calls.  I call to load two items separately and when my callback is hit, I add the new item to my list which is bound to my RadTileView control.  Here are some code snippets:

    XAML
    <telerik:RadTileView ItemsSource="{Binding GraphList}"  />

    ViewModel
    In the constuctor:
    GraphList = new List<IChart>();

    MyObject.GetDataAsync(ID1, MyCallback1);
    MyObject.GetDataAsync(ID2, MyCallback2);

    in my callback, I grab the item and add it to 'GraphList'.  Then I call NotifyPropertyChanged() to indicate that GraphList has changed.

    public List<IChart> GraphList { get; set; }

    Here is the issue...if I do it as specified above, nothing shows up in the TileView control.  However, if I instantiate GraphList in either of my callback methods rather than the constructor, I'll see the item that was returned to that callback method.  If I instantiate GraphList in the constructor, I see nothing.  Via debug, I have confirmed that GraphList is getting properly loaded from both callbacks (i.e. it contains 2 items when the second callback is completed). 

    Thoughts?
  2. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 05 May 2011 Link to this post

    Hi Brian,

     You should use INotifyPropertyChanged when you really change a property - if it's a value type when you change its value and if it's a reference type(like List) when you change the reference. Lets say you have a List Foo, when you add an item to Foo you don't change it - it's still Foo and it have the same reference as before so the INotifyPropertyChanged won't work. When you change collections your collection should implement the INotifyCollectionChanged interface and the List does not.
    I'll advise you to change your GraphList from List<IChart> to ObservableCollection<IChart> or if don't want to use ObservableCollection you should create your own collection which implements the INotifyCollectionChanged and whenever you change its items you should fire the NotifyCollectionChanged().
    If you need further assistance feel free to ask.

    All the best,
    Zarko
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Brian
    Brian avatar
    73 posts
    Member since:
    Sep 2010

    Posted 05 May 2011 Link to this post

    Yep, that solved the issue for us.  I really appreciate your assistance.
Back to Top