IsKeyboardFocusWithin property in DataGrid is always false

Nov 20, 2009 at 10:00 AM

Hello everybody.

I wanted to change my selected DataGridRow background when the focus is outside the DataGrid. This is the default convention used by ListBox, ListView and TreeView, a blue selection when the focus is inside the parent control and a gray one when it's outside of it.

Searching on the web, I found that most people use a trigger on DataGrid.IsKeyboardFocusWithin, so that when it's true you have the blue backgroun and when it's false the gray one.

So, I implemented that trigger, only to see that now my selection is always gray. The problem is that DataGrid.IsKeyboardFocusWithin is always false no matter how many times I click on it. I've even checked it using Snoop. I tried setting FocusManager.IsFocusScope to true to no avail. I even thought the problem could be that DataGrid.IsReadOnly is true, so I tried setting it to false to check what would happen, but I only received some errors on the debug console and it didn't fix anything.

What could be possibly happening?

 

Thanks,

-Sergi Díaz

Nov 20, 2009 at 10:04 AM

Now I feel like an idiot. I was setting DataGridCell.Focusable to false. No wonder they weren't catching the focus...

Nothing to see here ;).

 

-Sergi Díaz