wpf 如何使 XamDataGrid 仅在第二次单击时编辑单元格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16450605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:45:27  来源:igfitidea点击:

How to make XamDataGrid edit a cell only on the second click

wpfxamlinfragistics

提问by Dov

I have an Infragistics XamDataGrid(using 2011.1 WPF), which I'd like to mimic the behavior of a file browser (Finder/Windows Explorer) or iTunes, where a single click selects a row, and a second click opens the field's editor. As I have it currently defined, a single click immediately begins editing the selected row. I defined my grid like so:

我有一个 Infragistics XamDataGrid(使用 2011.1 WPF),我想模仿文件浏览器(Finder/Windows 资源管理器)或 iTunes 的行为,单击一次选择一行,第二次单击打开该字段的编辑器。正如我目前定义的那样,单击一下即可立即开始编辑所选行。我像这样定义了我的网格:

<ig:XamDataGrid>
    <ig:XamDataGrid.FieldLayoutSettings>
        <ig:FieldLayoutSettings AutoGenerateFields="False" RecordSelectorLocation="None" />
    </ig:XamDataGrid.FieldLayoutSettings>
    <ig:XamDataGrid.FieldLayouts>
        <ig:FieldLayout>
            <ig:Field Name="Name" Width="*" />
        </ig:FieldLayout>
    </ig:XamDataGrid.FieldLayouts>
</ig:XamDataGrid>

回答by Stefan

I can suggest you set the XamDataGrid's FieldSettings' CellClickAction to SelectRecord and create a Style for the CellValuePresenter and handles its PreviewMouseLeftButtonDown event. In the handler you should check if the clicked Record is Active and if so you can start Edit mode. You can define the XamDataGrid like this:

我建议您将 XamDataGrid 的 FieldSettings 的 CellClickAction 设置为 SelectRecord 并为 CellValuePresenter 创建样式并处理其 PreviewMouseLeftButtonDown 事件。在处理程序中,您应该检查单击的记录是否处于活动状态,如果是,您可以启动编辑模式。您可以像这样定义 XamDataGrid:

<igDP:XamDataGrid >
    <igDP:XamDataGrid.Resources>
        <Style TargetType="{x:Type igDP:CellValuePresenter}">
            <EventSetter Event="PreviewMouseLeftButtonDown" Handler="CellValuePresenter_PreviewMouseLeftButtonDown"/>
        </Style>
    </igDP:XamDataGrid.Resources>
    <igDP:XamDataGrid.FieldSettings>
        <igDP:FieldSettings CellClickAction="SelectRecord"/>
    </igDP:XamDataGrid.FieldSettings>
</igDP:XamDataGrid>

And use the following event handler:

并使用以下事件处理程序:

private void CellValuePresenter_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    if ((sender as CellValuePresenter).Record.IsActive)
    {
        (sender as CellValuePresenter).Editor.StartEditMode();
    }
} 

Also I can suggest you write into Infragistics forums, when you have an Infragistics related question:

另外,当您有与 Infragistics 相关的问题时,我还建议您写信到 Infragistics 论坛:

http://www.infragistics.com/community/forums/default.aspx?GroupID=38

http://www.infragistics.com/community/forums/default.aspx?GroupID=38

because it is easier for tracking and you will get an answer from an Infragistics employee.

因为跟踪更容易,而且您会从 Infragistics 员工那里得到答案。

Hope this helps you.

希望这对你有帮助。