本文介绍了Datagridrow动画不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我试图在属性的值时动画一行 LastUpdated  是
已更改。我遇到的问题是动画只在我向网格添加一行时运行,但是当我将属性更改为test时,动画不起作用。问题是什么? Thx!

<DataGrid.RowStyle>
    <Style TargetType="{x:Type DataGridRow}"
           BasedOn="{StaticResource MetroDataGridRow}">
        <Style.Triggers>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding LastUpdated, Converter={StaticResource ValueHasChangedConverter}}"
                               Value="True" />
                </MultiDataTrigger.Conditions>
                <MultiDataTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard AutoReverse="True"
                                    RepeatBehavior="3x">
                            <ColorAnimation From="Transparent"
                                            Duration="00:00:0.5"
                                            To="{StaticResource AccentColor}"
                                            Storyboard.TargetProperty="(DataGridRow.Background).(SolidColorBrush.Color)" />
                        </Storyboard>
                    </BeginStoryboard>
                </MultiDataTrigger.EnterActions>
            </MultiDataTrigger>
        </Style.Triggers>
    </Style>
</DataGrid.RowStyle>

public class ValueHasChangedConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return true;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return DependencyProperty.UnsetValue;
    }
}

public class OrderStatusDataWrapper : INotifyPropertyChanged
{

    private DateTime _lastUpdated;
    public DateTime LastUpdated
    {
        get => _lastUpdated;
        set
        {
            _lastUpdated = value;
            RaisePropertyChanged();
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    private void RaisePropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

推荐答案

<Condition Binding="{Binding LastUpdated, Converter={StaticResource ValueHasChangedConverter}}"
                               Value="True" />


public class ValueHasChangedConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return true;
    }


这篇关于Datagridrow动画不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 17:39