Binding ItemsSource to a gridview in a RadWindow

5 posts, 0 answers
  1. Tobania
    Tobania avatar
    160 posts
    Member since:
    Apr 2010

    Posted 24 Jun 2010 Link to this post


    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> 

    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?

  2. Hristo
    Hristo avatar
    832 posts

    Posted 29 Jun 2010 Link to this post

    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.

    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. Tobania
    Tobania avatar
    160 posts
    Member since:
    Apr 2010

    Posted 29 Jun 2010 Link to this post

    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.

  4. Ben
    Ben avatar
    1 posts
    Member since:
    Jan 2011

    Posted 12 Jan 2011 Link to this post

    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
  5. Miroslav Nedyalkov
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 14 Jan 2011 Link to this post

    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>>
Back to Top