代码之家  ›  专栏  ›  技术社区  ›  flobadob

样式范围问题

  •  1
  • flobadob  · 技术社区  · 14 年前

    我有几个文本块,绑定到不同的东西。两个文本块应用了相同的样式。在样式中有一个eventtrigger,当绑定值更新时,它会闪烁文本。但是当一个textblock的值更新时,两个textblocks都会闪烁。我以为只有一个文本块会闪现。有什么想法吗?

        <Style x:Key="flashingTextBlock" TargetType="TextBlock">
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="Foreground" Value="#333333" />
            <Style.Triggers>
                <EventTrigger RoutedEvent="Binding.TargetUpdated">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation     
                                    Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)"
                                    To="Orange"              
                                    Duration="0:0:1"
                                    AutoReverse="True"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Style.Triggers>
        </Style>
    
    <TextBlock Text="{Binding Path=PcName, NotifyOnTargetUpdated=True}" 
            Style="{StaticResource flashingTextBlock}"/>
    <TextBlock Text="{Binding Path=Time, NotifyOnTargetUpdated=True}" 
            Style="{StaticResource flashingTextBlock}"/>
    
    1 回复  |  直到 14 年前
        1
  •  1
  •   Henk Holterman    14 年前

    基本上我不能复制这个(用类似的配置)。

    我建议你核实一下到底发生了什么。可能是您的codebehind(ViewModel)正在热情地调用PropertyChanged。