如何在 RibbonButton.Click 上提高 DataGrid.LostFocus?

发布于 2024-10-11 08:04:07 字数 662 浏览 3 评论 0原文

以下代码使用 ToolBar 并正确导致 DataGrid.LostFocus(通过在执行命令之前提交任何未提交的行编辑);

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

但是,我现在尝试使用 Ribbon(oct10 版本)执行相同的操作,但以下内容不会导致 DataGrid.LostFocus 引发;

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

如何使用功能区引发此事件?我尝试将 IsFocusScope 移动到其他级别(Ribbon、RibbonTab、RibbonButton),但无济于事。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扶醉桌前 2024-10-18 08:04:07

不喜欢这个,因为需要后台代码,但没有任何其他答案;

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

以及后面的代码;

private void dropFocus(object sender, RoutedEventArgs e)
{
  Keyboard.Focus(focusControl);
}

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);
}
城歌 2024-10-18 08:04:07

虽然这个问题已经有6年多了,但我也想发布我的解决方案:
只需将 PreviewMouseDown 的事件处理程序添加到 RibbonWin 并将焦点设置为 null...

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

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文