Home Forums WPF controls Xceed DataGrid for WPF DataGrid event and Properties using MVVM

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #37619 |

    I have a WPF DataGrid, ver 3.7 as we are still using vs2008 and .net 3.5

    1. I need to hook column properties like enable, visible etc to properties in my ViewModel

    2. I need to handle events like Row or Cell double-clicked using ICommand objects in my viewModel

    are things like these do-able with the DataGrid

    Please help.  Sample code will be appreciated

    Thanks

    Imported from legacy forums. Posted by Elbino (had 691 views)

    Diane [Xceed]
    Moderator
    Post count: 1353

    Hi Elbino,

    Here are the answers to your questions:

    1. Soon it will be possible to do things like this:

       <xcdg:DataGridControl Name=”grid” ItemsSource=”{Binding Collection}”
                                          SelectedItem=”{Binding SelectedItem, Mode=TwoWay}”>
          <xcdg:DataGridControl.Resources>
             <xcdg:Column x:Key=”columnTest” FieldName=”.” ReadOnly=”{Binding IsReadOnly}” />
          </xcdg:DataGridControl.Resources>
          <xcdg:DataGridControl.Columns>
             <StaticResource ResourceKey=”columnTest”/>
          </xcdg:DataGridControl.Columns>
       </xcdg:DataGridControl>

     or

       <xcdg:DataGridControl Name=”grid” ItemsSource=”{Binding Collection}”
                                          SelectedItem=”{Binding SelectedItem, Mode=TwoWay}”>
          <xcdg:DataGridControl.Columns>
             <xcdg:Column FieldName=”.”
                                   ReadOnly=”{Binding RelativeSource={RelativeSource Self}, Path=DataGridControl.DataContext.IsReadOnly}” />
          </xcdg:DataGridControl.Columns>
       </xcdg:DataGridControl>

    But while waiting for the next major version to come out, we found this post that shows workarounds to have a DataContext on an object that doesn’t have one:
    http://www.codeproject.com/KB/WPF/ArtificialInheritanceCxt.aspx

    2. You could subscribe to the PreviewMouseDoubleClick event on the DataGridControl and call the command of your ViewModel. Or you could derive from Row/Cell and add properties to bind to the Command directly.

    Unfortunately, we don’t have any MVVM specific samples yet, but I will keep a note to update this forum thread when we do have some.

     

    Imported from legacy forums. Posted by Diane [Xceed] (had 2201 views)

    chaperona
    Keymaster
    Post count: 3

    Look at this page in our documentation which lists the improvements we have made to better support MVVM scenarios.

    You can also look at our MVVM sample for examples on how to use the DataGrid in MVVM (normally found in C:\Xceed Samples\Xceed DataGrid for WPF v(version number)\(development language)\MVVM).

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.