Wpf – EditMode in DataGrid with single click via XAML triggers

wpfwpfdatagridxaml

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)..!

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>

Thanks.

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'."

Best Answer

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>

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>
Related Topic