Datagridrow动画无法正常工作

时间:2018-07-26 17:23:35

标签: c# wpf xaml

当属性LastUpdated的值更改时,我试图为行设置动画。我的问题是动画仅在向网格添加一行时才运行,但是当我更改属性以进行测试时,动画不起作用。有什么问题吗?

<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));
    }
}

0 个答案:

没有答案