views:

355

answers:

3

I have a program in which a user selects a row in a Datagrid and then clicks a "Start Recording" button. While "recording" is happening, they are not allowed to change the value selected in the datagrid, so I set IsEnabled to false. However, when the datagrid is set to be disabled, it deselects the selected row, which screws up any bindings I have to the datagrid's SelectedItem propery.

Is there any way to keep the datagrid row selected even though the control is disabled?

Edit: This does not happen in Windows Vista, but it does in Windows 7.

A: 

If you really want to 'record' actions but still keep visuals and interactions looking the same, why don't you just add a check to the event fired on selection to ensure that recording is not taking place and set e.Handled = true.

Alternatively you could set IsHitTestVisible = false and prevent them from taking actions in the control instead of disabling it outright.

Hope that helps.

Jeff Wain
Setting e.Handled in the SelectionChanged event did not work, as it seems that event is not called until the selection is already changed (ie, after it's too late). I couldn't find any kind of equivalent of "PreviewSelectionChanged" in the DataGrid.On the other hand, setting IsHitTestVisible rather than IsEnabled seems to work OK, except that the visual aspect doesn't change. I guess that will be OK for my purposes.Thanks!
Mike
Ah, didn't realize you were trying to change some visual state. You may want to verify that some additional event is not firing when you disable the DataGrid. I just checked within one of our implementations to see if this deselected rows, and it did not.
Jeff Wain
A: 

Sorry I know this post is a little old, but I couldn't find another solution to this anywhere else.

It doesn't seem to be related to Vista\7, but to the Feb. release of the Toolkit.

You can set IsHitTestVisible = false as Jeff Wain suggests, but as Mike noted it doesn't appear different. Also, It doesn't disable Keyboard input.

My solution is to put the DataGrid in a Grid within the same row and column as a semitransparent gray rectangle (This will make them on top of one another). You have to put the rectangle in the Grid second to make sure it is on top of the DataGrid. When I want to 'disable' it I make the rectangle visible. This will make the list look dimmed and disable mouse inputs, but it still doesn't disable keyboard input.

To disable the keyboard I have to intercept 'PreviewKeyDown' and set e.Handdled = true. This will not allow anything else to be selected but will still do some interesting things when you tab to it (like tab no longer working). Perhaps setting it to not be a tab stop and not focusable will also fix this, but disabling selection is all I really care about.

Neal
A: 

IsHitTestVisible=false disables mouse inputs.

For disabling keyboard inputs set Focusable=false.

Both should be set via a style in ElementStyle and/or ElementEditingStyle for builtin datagrid columns inorder for the child control (textbox, checkbox, etc) to not accept input.

You'll most likely have to use a trigger in the style and bind it to some IsRecording value.

Also you could, in the same style, change the appearnce of the "disabled" controls by setting their Opacity=0.4, this gives somewhat of a disabled feel to them.

Marko