This is a migrated thread and some comments may be shown as answers.

TileView Bug with MVVM?

2 Answers 56 Views
TileView
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 04 May 2011, 10:48 PM
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 Answers, 1 is accepted

Sort by
0
Zarko
Telerik team
answered on 05 May 2011, 10:45 AM
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
0
Brian
Top achievements
Rank 1
answered on 05 May 2011, 02:33 PM
Yep, that solved the issue for us.  I really appreciate your assistance.
Tags
TileView
Asked by
Brian
Top achievements
Rank 1
Answers by
Zarko
Telerik team
Brian
Top achievements
Rank 1
Share this question
or