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

WPF GridView Documentation

1 Answer 110 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 1
Joseph asked on 29 Mar 2013, 05:21 PM
Hello,

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.

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 01 Apr 2013, 06:45 AM
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:

  <UserControl.Resources>
        <my:MyViewModel x:Key="MyViewModel"/>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot"
          Background="White"
          DataContext="{StaticResource MyViewModel}">
 
        <telerik:RadGridView Name="clubsGrid"
                             ItemsSource="{Binding Clubs}"/>
</Grid>
 
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,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Joseph
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or