1

The following code uses a ToolBar and correctly causes DataGrid.LostFocus (there by committing any uncomitted row-edits before the command is executed);

<Toolbar FocusManager.IsFocusScope="False">
  <Button Command="{Binding CommandName}" />
</ToolBar>
<DataGrid ... />

However, I am now trying to do the same using the Ribbon (oct10 release), but the following does not cause DataGrid.LostFocus to be raised;

<Ribbon>
  <RibbonTab>
    <RibbonGroup FocusManager.IsFocusScope="False">
      <RibbonButton Command="{Binding CommandName}" />
    </RibbonGroup>
  </RibbonTab>
</Ribbon>
<DataGrid ... />

How can I raise this event using the Ribbon? I have tried moving the IsFocusScope through the other levels (Ribbon, RibbonTab, RibbonButton) to no avail.

Stafford Williams
  • 9,696
  • 8
  • 50
  • 101

2 Answers2

1

Altough this question is over 6 years old, I want to post my solution too: Just add an Eventhandler for PreviewMouseDown to the RibbonWin and set the focus to null...

private void RibbonWin_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    FocusManager.SetFocusedElement(this, null);
}
Galjuergen
  • 11
  • 1
1

Don't like this due to the need for code behind, but in the absence of any other answers;

<Ribbon>
  <RibbonTab>
    <RibbonGroup>
      <RibbonButton Command="{Binding CommandName}" Click="dropFocus" />
    </RibbonGroup>
  </RibbonTab>
</Ribbon>
<Control IsTabStop="False" Name="focusControl"/>
<DataGrid ... />

And the code behind;

private void dropFocus(object sender, RoutedEventArgs e)
{
  Keyboard.Focus(focusControl);
}
Stafford Williams
  • 9,696
  • 8
  • 50
  • 101