gpt4 book ai didi

c# - WPF 动画未触发

转载 作者:行者123 更新时间:2023-12-03 10:28:55 25 4
gpt4 key购买 nike

所有我有以下DataGrid

<DataGrid x:Name="resourceDataGrid" 
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AutoGenerateColumns="false"
GridLinesVisibility="None"
RowHeaderWidth="0"
CanUserAddRows="True"
CanUserDeleteRows="True"
ItemsSource="{Binding Path=Resources,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged,
IsAsync=True}">
<DataGrid.Columns>
<DataGridTemplateColumn CellTemplate="{StaticResource readOnlyCellUpdatedStyle}" IsReadOnly="True"/>
<!--<DataGridTextColumn Header="KeyIndex" Binding="{Binding KeyIndex}" IsReadOnly="True"/>--> <- What I did have...
<DataGridTextColumn Header="FileName" Binding="{Binding FileName}" IsReadOnly="True"/>
<DataGridTextColumn Header="ResourceName" Binding="{Binding ResourceName}" IsReadOnly="False"/>
<controls:CollectionTextColumn Collection="ResourceStringList" Visibility="Collapsed"/>
</DataGrid.Columns>
</DataGrid>

当数据集中的一行被删除时,我想重新编号 KeyIndex柱子。当这种重新编号发生时,我想优雅地闪烁更新的单元格,让用户知道然后这些值被更新。

我创建了以下 DataTemplate
<DataTemplate x:Key="readOnlyCellUpdatedStyle">
<TextBlock Text="{Binding KeyIndex, NotifyOnSourceUpdated=True, Mode=TwoWay}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<EventTrigger RoutedEvent="Binding.SourceUpdated">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color"
Duration="0:0:0.3"
From="White"
To="Red"
RepeatBehavior="3x"
AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</DataTemplate>

绑定(bind)仍然适用于 KeyIndex但是当我更新 KayIndex ViewModel 中的值现在会发生动画,该值会发生变化。 为什么 KeyIndex 时动画不触发更新了吗?

谢谢你的时间。

最佳答案

您将需要使用 NotifyOnTargetUpdatedBinding.TargetUpdated .并且不要忘记先设置背景值,否则为颜色设置动画会引发异常。

  • Binding.SourceUpdated元素 -> 对象
  • Binding.TargetUpdated对象 -> 元素

  • 有时会变得非常困惑
    <DataTemplate x:Key="readOnlyCellUpdatedStyle">
    <TextBlock Text="{Binding KeyIndex, Mode=TwoWay,NotifyOnTargetUpdated=True}">
    <TextBlock.Style>
    <Style TargetType="TextBlock">
    <Setter Property="Background" Value="White"/>
    <Style.Triggers>
    <EventTrigger RoutedEvent="Binding.TargetUpdated">
    <BeginStoryboard>
    <Storyboard>
    <ColorAnimation Storyboard.TargetProperty="Background.Color"
    Duration="0:0:0.3"
    From="White"
    To="Red"
    RepeatBehavior="3x"
    AutoReverse="True"/>
    </Storyboard>
    </BeginStoryboard>
    </EventTrigger>
    </Style.Triggers>
    </Style>
    </TextBlock.Style>
    </TextBlock>
    </DataTemplate>

    关于c# - WPF 动画未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18135965/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com