I moved my vanilla SL3 grid to XamWebGrid and I'm very disappointed in its compatibility with the regular grid.
I'm using MVVM and I use an ICollectionView to be able to keep track of the current item and be able to sort from the ViewModel. Sorting from the VM to the grid seems to work OK (I haven't cheked yet the opposite).
My problem is that I can't see any way to bind the current grid row to the item, which was handled by the vanilla grid for me. Do I have to handle that myself? I think the XamWebGrid should at least have the basic features of the vanilla SL3 grid.
This worked for me if you want to directly access underlying data object corresponding to a row.
<ig:XamGrid x:Name="dataGrid" AutoGenerateColumns="False" Grid.Row="3" Margin="8,0,8,8"ItemsSource="{Binding SearchResultViewModel.Summaries}"cmd:XamGridCellDoubleClick.Command="{Binding OpenProject}"cmd:XamGridCellDoubleClick.CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=SelectionSettings.SelectedRows[0].Data}">
Yeah, I tried that first, but got a null object returned. I ended up using a hack, but a least for now it works. I modified my ActiveCellChanged event handler to extract the active row. Then forced it to the CommandParameter property (I'm using Prism for my command behaviors). This sits in an infrastructure class, so it can be used by other modules. I just didn't want a XamWebGrid object being passed to my VM since I don't want the VM to know about anything about the UI. Here's my code snippet. I'm keeping track of the current row index since I only want this triggered on row changes:
void targetGrid_ActiveCellChanged(object sender, EventArgs e) { XamWebGrid grid = sender as XamWebGrid; int rowIndex = grid.ActiveCell.Row.Index;
if (_CurrentRow == -1 || _CurrentRow != rowIndex) { _CurrentRow = rowIndex; this.CommandParameter = (object)grid.ActiveCell.Row.Data; this.ExecuteCommand(); } }
Off the top of my head, add a Path attribute to your Binding pointing to the ActiveCell of the grid
Path="ActiveCell"
Darrell,
I'm also using the XamWebGrid with MVVM and have the same request.
I was able to implement some behaviors that allow me to execute a command when the row changes based on the following blog:
http://weblogs.asp.net/alexeyzakharov/archive/2009/06/06/silverlight-tips-amp-tricks-make-silverlight-datagrid-be-more-mvvm-friendly.aspx
I made the changes so that a command is fired on the the XamWebGrid.ActiveCellChanged event.
My problem at the moment is trying to figure out the XAML binding statement that returns the current Row. If I have the xaml snippet:
<igGrid:XamWebGrid x:Name="RequestedDataGrid" d:LayoutOverrides="Width" ItemsSource="{Binding AuditList, Mode=TwoWay}" AutoGenerateColumns="False" Grid.Row="1" igBehavior:DataGridSelectionChanged.Command="{Binding MyTestCommand}" igBehavior:DataGridSelectionChanged.CommandParameter="{Binding RelativeSource= {RelativeSource Self}}"> <igGrid:XamWebGrid.EditingSettings> <igGrid:EditingSettings AllowEditing="Cell" IsMouseActionEditingEnabled="SingleClick" /> </igGrid:XamWebGrid.EditingSettings> <igGrid:XamWebGrid.Columns> <igGrid:TextColumn Key="CheckDate" IsReadOnly="True" FormatString="{}{0:d}" /> <igGrid:CheckBoxColumn Key="ReTransmit" /> </igGrid:XamWebGrid.Columns> </igGrid:XamWebGrid>
The CommandParameter will return a reference to the entire grid to my MyTestCommand method as a parameter. What would be the binding statement syntax that returns the current row? I was able to get the row from the grid passed to the method by getting the grid.ActiveCell.Row.Data property. But I don't want to pass the grid to my VM, I just want the current row object. Any help would be appreciated.
Bob
Currently the xamWebGrid does not support this due to hierarchy and multiple selection. We are looking into a way to support this in a future release.