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

ItemsSource

4 Answers 806 Views
GridView
This is a migrated thread and some comments may be shown as answers.
marc
Top achievements
Rank 1
marc asked on 23 Aug 2011, 12:07 PM
Hi, I am prototyping with radgridview and am not very wpf experienced. I have a simple problem I can't solve and am hoping someone can give me a hint.

<telerik:RadGridView x:Name="Navigation"
                    AutoGenerateColumns="False"
                    ItemsSource="{StaticResource data}"
                    >

"data" is an ObservableCollection and I was expecting the grid to update, when the collection gets updated. Data already in the list after initialisation is shown. I guessed this does not work, as its a StaticResource, but with DynamicResource it also does not work.

However if i use c# code it works:

this.Navigation.ItemsSource = this.data;

Now its obvious to me I am doing something wrong with the ItemsSource in xaml, but I just have no clue what I should be doing...

4 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 23 Aug 2011, 12:36 PM
Hi Marc,

I suppose that this setup will not work with any ItemsControl, but that's another story.

RadGridView definitely works with an ObservableCollection<T>. If it did not it would be totally useless. I am not really sure why you want to place the data as a static or dynamic resource, but that is not the best way in my opinion.

I have attached a sample project that shows how you should bind to a property residing on your view model. 

To learn more about Data Binding, please read this.

I hope this helps.

Kind regards,
Ross
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
marc
Top achievements
Rank 1
answered on 23 Aug 2011, 12:57 PM
thanks you for the sample project. I am still a little stunned that what I was trying astonishes you. I assume I must have overlooked a conceptual aspect. To me the two approaches seem identical (the use of static/dynamic resource is possibly entirely wrong).

is there no equivalent in xaml for the code I write in c#?

this.Navigation.ItemsSource = this.data;

I assumed i could set the ItemsSource in xaml in a similar way, as I can reference the data object. I am not too fond of microsoft documentation, but I will try to get through it ;) 
0
Rossen Hristov
Telerik team
answered on 23 Aug 2011, 01:50 PM
Hi Marc,

I am not stunned at all. 

Please, replace RadGridView with any other items control such as a stock ListBox or the stock DataGrid and tell me what happens. Do they work? Does the problem stem from RadGridView or from something else?

I understand that you are not fond of reading documentation, but if you take your time and read the things explained in the link I have provided you would not be asking these questions. You can't learn WPF by not reading about WPF. Trying every possible combination until something finally works is not the correct way to learn a new technology.

In XAML you use Bindings, you can't set things directly like that. There are many different bindings -- binding to a resource, binding to a property on the data context, binding to a property on another element (ElementName binding), TemplateBinding when you are inside a control template and so on.

But WPF Bindings are not a Telerik-related topic. Telerik forums are for Telerik product-related discussions.

Please, read the link that I have provided in order to learn how WPF works and in case you have other general WPF questions, my suggestion would be to please use the appropriate Microsoft forums.

If you have questions that are particularly related to Telerik controls we would be more than glad to answer them here. That's the purpose of these forums.

I hope this helps.

All the best,

Ross
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
marc
Top achievements
Rank 1
answered on 23 Aug 2011, 01:53 PM
sure I understand that. I had simply assumed my question would be easy to answer. This assumption is obviously wrong, sorry for wasting your time. I never assumed this was a telerik problem.
Tags
GridView
Asked by
marc
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
marc
Top achievements
Rank 1
Share this question
or