views:

108

answers:

1

How Can I know if the DataGridCell is currently in edit mode (not IsSelected), I mean, for example a DataGridTextColumn cell is clicked it becomes a TextBox and not a TextBlock, that's what I call IsEditMode. I wanna set a trigger-setter for this mode.

EDIT: I tried to set a general style for DataGridCell.IsEditing but it doesn't seem to do anything.

Here is a snippet of my current code:

<Style TargetType="{x:Type tk:DataGridCell}">
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Background" Value="{x:Null}"/>
        </Trigger>
        <Trigger Property="IsEditing" Value="True">
            <Setter Property="BorderBrush" Value="#FF62B6CC"/>
            <Setter Property="Background" Value="#FFF4F4F4"/>
        </Trigger>
    </Style.Triggers>
    <Setter Property="Foreground" Value="Black"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="BorderThickness" Value="0.5"/>
    <Setter Property="BorderBrush" Value="{x:Null}"/>
</Style>

Thanks.

A: 

Hi Shimmy,

If you take a look at DataGridCell.cs file, IsEditing should be good way to find out if cell is in edit mode. But you can't set this property from style, because there is local value assignment in DataGridCell class (which has higher priority from style setter).

So, the answer would be: it should work from trigger, but it will not from the style setter.

Update: Shimmy, it really works. Snoop your application, make sure DataGridCell is using your implicit style. Select DataGridCell in the tree, and check its background property. Every time you go in Edit mode it is updated. But you don't see it, by default, since TextBox doesn't inherit Background property. But that's another story. I think you can tweak CellEditingTemplate to make it working.

Anvaka
What I set style I meant via a property trigger.
Shimmy
Could you post a code snippet?
Anvaka
You got it boss.
Shimmy
:) I've updated the answer
Anvaka