I used dattriggers in the XamDataGrid for WPF but could not use
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
in the XamGrid. Are there any plans to allow datatriggers in the XamGrid? I wanted to allow or disallow editing of cells based a condition of the data and had to use the ActiveCellChanging and CellEnteringEditMode events to prevent editing of a cell based on a data condition. By the way, setting e.cancel = true in the ActiveCellChanging event did not prevent the cell from Activating, I also had to trap in the CellEnteringEditMode event.
Thank you for helping me with my issue. While your answer does prevent editing it does it at the grid level which is too big a scope. There are other fields that are still editable and I would need to intercept for every editable cell and make sure editing was turned on.
Here is how I accomplished what I needed. I though that cancelling in the ActiveCellChanging event would work but canceling the CellEnteringEditMode seems to do the trick.
private void TimeTransferDataGrid_CellEnteringEditMode(object sender, BeginEditingCellEventArgs e) { // If logged in user is not the subject of the transfer do not allow them to edit these columns if (e.Cell != null && (e.Cell.Column.Key == "ReasonCode" || e.Cell.Column.Key == "ReasonDescription")) { if (MainPage.CurrentAppUser.EmpCode != e.Cell.Row.Cells["EvcCode"].Value.ToString()) { e.Cancel = true; } // If reject flag has been choosen do not allow entry if (e.Cell.Row.Cells["RejectTransfer"].Value.ToString() == "1" || e.Cell.Row.Cells["ApproveTransfer"].Value.ToString() == "0") { e.Cancel = true; } } }
Hello drdonna,
I was looking into your questions, and I can see the issue you are describing. Still please have in mind that the using of a DataTrigers is a Silverlight limitation, so their support isn’t currently built in our XamGrid. However after some investigation of the issue I believe that the functionality you are requiring can be achieved by handling the CellClicked event of the XamGrid and change the AllowEdit property of the control from the handler:
private void xamGrid_CellClicked(object sender, CellClickedEventArgs e)
{
if(e.Cell.Value....)
xamGrid.EditingSettings.AllowEditing = EditingType.None;
else
xamGrid.EditingSettings.AllowEditing = EditingType.Cell;
}
If you need any further assistance on this matter, please feel free to ask.