通过XAML触发器单击即可在DataGrid中使用EditMode [英] EditMode in DataGrid with single click via XAML triggers

查看:78
本文介绍了通过XAML触发器单击即可在DataGrid中使用EditMode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有DataGrid,如果要编辑单元格中的值,则必须对此进行双击,并且光标出现在此处(单击以选择相应的单元格即可。)。

I have DataGrid, if I want edit value in cell I must perform double click for on this and cursor appear here (with one click it just select appropriate cell)..!

我是否可以(通过Xaml触发器)单击单元格而不仅仅是选中它们,而是立即进入EditMode,并且当我在带有箭头的单元格之间切换时,它们也进入EditMode吗?

May I make (via Xaml triggers) that with single click on cells they aren't just selected, but entered in EditMode at once and when I switch between cells with arrows they also enter in EditMode?

这里是我当前的修订代码

Here my current revised code

   <Page.Resources>
    <grd:LenghthToVisibility x:Key="LenghthToVisibility"/>
    <grd:StringToSystemIconConverter x:Key="StringToSystemIconConverter"/>
    <grd:booleanConverter x:Key="booleanConverter"/>
    <DataGrid.CellStyle>
        <Style TargetType="{x:Type DataGridCell}">
            <Setter Property="IsTabStop" Value="False" />
            <Setter Property="Focusable" Value="False" />
        </Style>
      <Style x:Key="RightCellStyle" TargetType="DataGridCell">
        <Setter Property="HorizontalAlignment" Value="Right" />
    </Style>
    <Style x:Key="RightAlignedCell" TargetType="{x:Type DataGridCell}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridCell}">
                    <Grid Background="{TemplateBinding Background}">
                        <ContentPresenter HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="DataGridCell.IsSelected" Value="True">
                <Setter Property="IsEditing" Value="True" />
                <Setter Property="Background" Value="#356815" />
                <Setter Property="Foreground" Value="#e2fce2" />
            </Trigger>
           </Style.Triggers>
    </Style>
        </DataGrid.CellStyle>
    </Page.Resources>

谢谢。

我有2个奇怪的地方错误并刷新上面的代码:
1)错误5在类型'DataGrid'中找不到可附加属性'CellStyle'。
2)错误2标签'DataGrid.CellStyle'不存在在XML名称空间'schemas.microsoft.com/winfx/2006/xaml/presentation'中。

I have 2 strange errors and refresh my code above: 1) "Error 5 The attachable property 'CellStyle' was not found in type 'DataGrid'. 2) "Error 2 The tag 'DataGrid.CellStyle' does not exist in XML namespace 'schemas.microsoft.com/winfx/2006/xaml/presentation'."

推荐答案

忽略 DataGridCell (关注内容)使用:

To ignore the DataGridCell (focus the content) use:

<DataGrid.CellStyle>
    <Style TargetType="{x:Type DataGridCell}">
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Focusable" Value="False" />
    </Style>
</DataGrid.CellStyle>

要在 ElementStyle / EditingElementStyle CellTemplate / CellEditingTemplate 环境设置 DataGridCell.IsEditing属性(如果已选中)为true:

To enter EditMode in an ElementStyle/EditingElementStyle or CellTemplate/CellEditingTemplate environment set DataGridCell.IsEditing Property to true if selected:

<Style x:Key="RightAlignedCell" TargetType="{x:Type DataGridCell}">
    ...
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="IsEditing" Value="True" />
            ...
        </Trigger>
    </Style.Triggers>
</Style>

这篇关于通过XAML触发器单击即可在DataGrid中使用EditMode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆