WPF GridView Documentation

2 posts, 0 answers
  1. Joseph
    Joseph avatar
    1 posts
    Member since:
    Feb 2008

    Posted 29 Mar 2013 Link to this post


    I am trying to use Telerik's WPF GridView control in a MVVM application.  I have two general questions:

    1) It seems that the XAML/WPF approach to MVVM requires the view to both a.) databind to the viewmodel, and b.) sink events from the viewmodel (that is, the view must respond to events from the view model).  Given that the Telerik WPF DataGrid obviously resides in the view, where does Telerik document the complete list of WPF DataGrid properties and methods?  Surely we can't be expected to infer the list of properties and methods from the samples?  Yet I cannot find what I normally think of as documentation.

    2) In the stock MVVM definitions and explanations I find on the internet, it seems that the MVVM advocates claim there is a "clear separation" of concerns between the view, the viewmodel, and the model.  But in the stock MVVM implementations, I find that the view's XAML invariably contains column names in the grid declaration.  That seems to violate MVVM, no? In these implementations, the view seems to be overly concerned with the model.  Wouldn't it be best if the view only knew how to query the collection of column names from the viewmodel? Then you wouldn't have to modify the view (that is, the XAML) every time a user requested a new column.

    Thanks.  I apologize in advance if these newbie-ish questions have been asked elsewhere; I queried the forums and could not find answers.
  2. Maya
    Maya avatar
    4062 posts

    Posted 01 Apr 2013 Link to this post

    Hello Joseph,

    There should be no problem to bind the grid without having any code in the code-behind. One way to go could be:

            <my:MyViewModel x:Key="MyViewModel"/>
        <Grid x:Name="LayoutRoot"
              DataContext="{StaticResource MyViewModel}">
            <telerik:RadGridView Name="clubsGrid"
                                 ItemsSource="{Binding Clubs}"/>
    Still, the exact implementation depends entirely on your settings and exact requirements. For example, if you are working with RadDataServiceDataSource, you can check out this article for a reference.
    Considering the methods, properties and events of the grid (or any other RadControl), you can run through the API Reference section, find the namespace you require - GridView for example - and get the list of the methods, properties, etc.
    As for getting columns for example in the code-behind, it does not actually interfere with the separation of concerns (View-ViewModel-Model, since usually (depending on the exact case), you do not mess up with the model or the view model. Nevertheless, you can always extend the functionality of the grid with an attached behavior for example and keep your code-behind clean. One example can be found in this demo. You can find more relate articles to attached behaviors here, here, here, etc.

    All the best,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top