Unable to animate a border's visibility or opacity
Posted: 14 Dec 2021, 12:54
I'm trying to "blink" a border either by animating it's visibility or by animating it's BorderBrush's opacity. So I have a DataTemplate for a "StereoMtd" datatype. When ErrorBorderFlash is true I try to load the storyboard but nothing happens. I'm able to blink the border opacity OK, but that blinks the entire thing, not just the border. I'm not sure how to specify the borderbrushes opacity. I've tried targetproperties like (Border.BorderBrush).(SolidColorBrush.Opacity) but that doesn't work either. Any ideas?
Code: Select all
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Modules.Measurement">
...
...
<!-- Blink animation -->
<!--<Storyboard x:Key="BlinkAnimation" RepeatBehavior="Forever">
<DoubleAnimation
Storyboard.TargetProperty="Opacity"
From="0"
To="1"
AutoReverse="True"
BeginTime="0:0:1"
Duration="0:0:0.08" />
<DoubleAnimation
Storyboard.TargetProperty="Opacity"
From="1"
To="1"
AutoReverse="True"
Duration="0:0:0.4" />
<DoubleAnimation
Storyboard.TargetProperty="Opacity"
From="1"
To="0"
AutoReverse="True"
Duration="0:0:0.08" />
</Storyboard>-->
<Storyboard x:Key="BlinkAnimation" RepeatBehavior="Forever">
<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/>
<DiscreteObjectKeyFrame KeyTime="00:00:10" Value="{x:Static Visibility.Collapsed}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
<DataTemplate
x:Name="StereoMtdDataTemplate"
DataType="{x:Type local:StereoMtd}">
<Border
x:Name="border"
BorderThickness="2"
BorderBrush="{StaticResource BackgroundBrush}"
Background="{StaticResource BackgroundBrush}"
CornerRadius="6"
HorizontalAlignment="Left"
VerticalAlignment="Center">
<TextBlock
Text="{Binding DisplayString}"
Margin="2"
Foreground="White"
FontSize="28"/>
</Border>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=ErrorBorder}" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="{StaticResource WarnBrush}"/>
<Setter TargetName="border" Property="BorderThickness" Value="2"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=ErrorBorderFlash}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource BlinkAnimation}"/>
</DataTrigger.EnterActions>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ResourceDictionary>