1

DataGrid当数据源更新时,我想加粗更改的单元格。我发现这<EventTrigger RoutedEvent="Binding.TargetUpdated">是我需要的事件。但是,我无法Storyboard使用该FontWeight物业。

这是我正在尝试的:

<EventTrigger RoutedEvent="Binding.TargetUpdated">
    <BeginStoryboard>
        <Storyboard>
            <Int32Animation Duration="00:00:05" 
                Storyboard.TargetProperty="(Int32)(DataGridCell.FontWeight)"  
                From="400" To="700" />
        </Storyboard>
    </BeginStoryboard>
</EventTrigger>

有人可以推荐如何修复上述问题或提出新的更聪明的方法来粗体更改单元格DataGrid吗?

4

1 回答 1

1

这对我有用...

我有资源...

   <Style TargetType="TextBlock" x:Key="ElementStyle">
       <Style.Triggers>
           <EventTrigger RoutedEvent="Binding.TargetUpdated">
                <BeginStoryboard>
                   <Storyboard>
                      <ObjectAnimationUsingKeyFrames
                          Duration="00:00:01"
                          Storyboard.TargetProperty="(TextElement.FontWeight)">
                             <DiscreteObjectKeyFrame 
                                KeyTime="00:00:00" 
                                Value="{x:Static FontWeights.Thin}" />
                             <DiscreteObjectKeyFrame 
                                KeyTime="00:00:00.5" 
                                Value="{x:Static FontWeights.Heavy}" />
                             <DiscreteObjectKeyFrame 
                                KeyTime="00:00:01" 
                                Value="{x:Static FontWeights.UltraBold}" />
                           </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                     </BeginStoryboard>                                
               </EventTrigger>
         </Style.Triggers>
  </Style>

将此分配给相关列,

  <toolkit:DataGridTextColumn 
        Binding="{Binding Quantity, NotifyOnTargetUpdated=True}" 
                          ElementStyle="{StaticResource ElementStyle}" />

编辑

因为上面的代码使默认值也加粗,我们有另一种方法来做到这一点,其中只有用户完成的更新才会触发单元格中的加粗。

风格

  <Style TargetType="Controls:DataGridCell" 
   BasedOn="{StaticResource {x:Type Controls:DataGridCell}}" 
   x:Key="CellBoldStyle">
<Style.Triggers>
    <EventTrigger RoutedEvent="Binding.SourceUpdated">
    <BeginStoryboard>
        <Storyboard>
        <ObjectAnimationUsingKeyFrames
            Duration="00:00:01"                                 Storyboard.TargetProperty
                                    ="(TextBlock.FontWeight)">
            <DiscreteObjectKeyFrame KeyTime="00:00:00.5" 
                                Value="{x:Static FontWeights.Normal}" />
            <DiscreteObjectKeyFrame KeyTime="00:00:01" 
                                Value="{x:Static FontWeights.Bold}" />
        </ObjectAnimationUsingKeyFrames>
        </Storyboard>
    </BeginStoryboard>
    </EventTrigger>
</Style.Triggers>
  </Style>

柱子

  <Controls:DataGridTextColumn 
             Binding="{Binding Side, Mode=TwoWay, 
                               NotifyOnTargetUpdated=True, 
                               NotifyOnSourceUpdated=True}" 
             CellStyle="{StaticResource CellBoldStyle}" />

限制

  1. 当您将虚拟化单元格滚动出滚动视图时,它们会失去粗体突出显示的效果。
  2. 甚至您的 TextBox 也显示 Bold value 。(我不知道这是否对你有限制!)
于 2012-10-22T07:41:19.950 回答