0

我有几个 DataGridTextColumn 的 DataGrid,其中一个是可编辑的。

我需要拦截正在编辑的单元格的 TextChanged 事件。

我尝试过编辑样式并添加

<EventSetter Event="TextChanged" Handler="TaskDescription_TextChanged"/>

但我得到

Cannot find the Style Event 'TextChanged' on the type 'System.Windows.Controls.DataGridCell'

除了双向绑定之外,是否有一种简单的方法可以通知 DataGridTextColumn 中的文本更改?

这是 XAML 代码:

    <Style x:Key="CenteredTextColumn" TargetType="{x:Type DataGridCell}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridCell}">
                    <Grid Height="30">
                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                            <ContentPresenter VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="VerticalAlignment" Value="Stretch"/>
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="Foreground" Value="Black"/>
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="{StaticResource SelectedCellBackground}"/>
                <Setter Property="Foreground" Value="White"/>
                <!--<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>-->
            </Trigger>
            <Trigger Property="IsKeyboardFocusWithin" Value="True">
                <!--<Setter Property="BorderBrush" Value="{DynamicResource {x:Static DataGrid.FocusBorderBrushKey}}"/>-->
            </Trigger>                  
            <Trigger Property="IsEditing" Value="True">
                <Setter Property="Background" Value="Transparent"/>
            </Trigger>  
        </Style.Triggers>
    </Style>

和事件设置器:

<Style x:Key="ProjectInfoEditeableCell" TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource CenteredTextColumn}">
        <EventSetter Event="TextChanged" Handler="TaskDescription_TextChanged"/>
    </Style>
4

0 回答 0