为什么DataGrid不会失去ToolBar-Click的焦点?

时间:2017-06-07 09:11:48

标签: c# .net wpf xaml datagrid

我有一个带有Button和DataGrid的ToolBar以及一个单独的Button。 enter image description here 当我编辑单元格(EditMode)然后单击“单独”按钮时,单元格将离开EditMode并提交更改。

但是当我单击ToolBar中的Button时,单元格不会离开EditMode并且不会提交更改。

单击ToolBar Button时,如何强制单元格提交更改?

XAML:

some-file.html

<div *ngFor="let widget of widgets">
  <section class="page subpage dashboard dashboard-page" style="overflow-y:hidden;">
    <div class="newDashbaord">
      <header>
        <div class="actions">
          <button class="control-btn borderless close-btn">
            <span #target class="icon-close action-icon" (click)="RemoveWidget(widget)"></span>
          </button>
        </div>
        <h1 class="table-heading">widget.name</h1>
      </header>
      <main>
      </main>
    </div>
  </section>
</div>

C#:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="DataContextSample" Height="543.538" Width="733.463"
        xmlns:self="clr-namespace:WpfApplication1">
    <DockPanel Margin="15">
        <ToolBar DockPanel.Dock="Top" Height="40">
            <Button Width="150" Height="20">ToolBarBUtton</Button>
        </ToolBar>
        <Button DockPanel.Dock="Top" Height="20" Width="150">Button</Button>
        <DataGrid DockPanel.Dock="Top" Name="DataGridJobConfigurations" ItemsSource="{Binding}"  VerticalScrollBarVisibility="Auto">
        </DataGrid>
    </DockPanel>
</Window>

1 个答案:

答案 0 :(得分:1)

您可以将FocusManager.IsFocusScope的附加Toolbar属性设置为false

<ToolBar DockPanel.Dock="Top" Height="40" FocusManager.IsFocusScope="False">
    <Button Width="150" Height="20">ToolBarBUtton</Button>
</ToolBar>