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

Binding ItemsSource to a gridview in a RadWindow

4 Answers 170 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Licenses
Top achievements
Rank 1
Licenses asked on 24 Jun 2010, 08:34 AM
Hello,

I have a problem involving databinding a GridView that is placed in a RadWindow.

When I create a GridView like this, everything works fine:
<telerikGrid:RadGridView Name="ResultsGrid" ItemsSource="{Binding Results}" AutoGeneratingColumn="ResultsGrid_AutoGeneratingColumn" IsReadOnly="True" VerticalAlignment="Stretch"></telerikGrid:RadGridView> 
 

As soon as the PropertyChanged-event of the Results is raised, my GridView databinds perfectly. However, when I put the same GridView in a RadWindow and call ShowDialog on the window, the GridView doesn't respond to the NotifyPropertyChanged-event anymore, and my GridView remains empty.

<telerikNavigation:RadWindow x:Name="ResultsWindow">  
    <telerikGrid:RadGridView Name="ResultsGrid" ItemsSource="{Binding Results}" AutoGeneratingColumn="ResultsGrid_AutoGeneratingColumn" IsReadOnly="True" VerticalAlignment="Stretch"></telerikGrid:RadGridView> 
</telerikNavigation:RadWindow> 

The solution I use now, is to manually listen to the propertychanged event and set the ItemsSource of the GridView:

_viewModel.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(ViewModel_PropertyChanged);  
 
...  
 
void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)  
{  
    if (e.PropertyName == "Results")  
        this.ResultsGrid.ItemsSource = ViewModel.Results;  

This works, but of course using Bindings for the ItemsSource would have been much easier. So I was wondering, is this a bug or did I do something wrong?

Greetings
Sodi

4 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 29 Jun 2010, 08:52 AM
Hello Sodi We,

When you call Show or ShowDialog RadWindow is moved to a popup controls. This mean that when RadWindow is remove from the visual tree and lose DataContext change notifications.
So in order to work you have to set RadWindow DataContext to the ViewModel that you use to bind the RadGridView.

Let us know if you need more information.

Greetings,
Hristo
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
Licenses
Top achievements
Rank 1
answered on 29 Jun 2010, 09:29 AM

I tried to add the following line before and after calling ShowDialog(), but with no success:

this.ResultsWindow.DataContext = this.DataContext; 

However, I will stick the solution in my first post, since there are also some other reasons now to set the itemssource explicitly instead of with bindings.

Sodi
0
Ben
Top achievements
Rank 1
answered on 12 Jan 2011, 06:53 AM
Hi
I am facing a similar issue. i have a list view in a radwindow. the listview only shows the values if i changes the height or width of the window. The databinding is working fine since it shows the data after i change the with or height of the window
Am i missing something here.
Any help is much appretiated
thanks
0
Miroslav Nedyalkov
Telerik team
answered on 14 Jan 2011, 01:40 PM
Hi Ben,

 I cannot clearly understand what your scenario is. Could you please open a support ticket and send us a sample project that represents the issue? This would help us better understand what goes wrong.

Kind regards,
Miroslav Nedyalkov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
Licenses
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Licenses
Top achievements
Rank 1
Ben
Top achievements
Rank 1
Miroslav Nedyalkov
Telerik team
Share this question
or