-
- darthmaule2
- Posts: 98
- Joined:
Unable to animate a border's visibility or opacity
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>
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Unable to animate a border's visibility or opacity
Hi,
The problem is that the storyboard repeat behavior and duration does not allow the Collapsed state to be visible, you should try with the following:
And also consider adding a StopStoryboard in the ExitActions to stop the forever animation:
The problem is that the storyboard repeat behavior and duration does not allow the Collapsed state to be visible, you should try with the following:
Code: Select all
<Storyboard x:Key="BlinkAnimation" RepeatBehavior="Forever">
<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="0:0:2" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="00:00:0" Value="{x:Static Visibility.Visible}"/>
<DiscreteObjectKeyFrame KeyTime="00:00:1" Value="{x:Static Visibility.Collapsed}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>Code: Select all
<DataTrigger.EnterActions>
<BeginStoryboard x:Name="BlinkAnim" Storyboard="{StaticResource BlinkAnimation}"/>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<StopStoryboard BeginStoryboardName="BlinkAnim"/>
</DataTrigger.ExitActions>-
- darthmaule2
- Posts: 98
- Joined:
Re: Unable to animate a border's visibility or opacity
That works but blinks the border and all it's child controls. I want to just blink the border somehow...
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Unable to animate a border's visibility or opacity
Hi, if you are interested in animating only the Border's BorderBrush then the template should look something like this:
Is that what you are looking for?
Code: Select all
<DataTemplate x:Name="StereoMtdDataTemplate" DataType="{x:Type local:StereoMtd}">
<DataTemplate.Resources>
<Storyboard x:Key="BlinkAnimation" RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Duration="0:0:2"
Storyboard.TargetProperty="BorderBrush.Opacity"
Storyboard.TargetName="border">
<DiscreteDoubleKeyFrame KeyTime="00:00:0" Value="1"/>
<DiscreteDoubleKeyFrame KeyTime="00:00:1" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</DataTemplate.Resources>
<Border x:Name="border"
BorderThickness="2"
BorderBrush="{StaticResource BackgroundBrush}"
Background="{StaticResource BackgroundBrush}"
CornerRadius="6"
HorizontalAlignment="Left"
VerticalAlignment="Center">
<TextBlock Text="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 x:Name="BlinkAnim" Storyboard="{StaticResource BlinkAnimation}"/>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<StopStoryboard BeginStoryboardName="BlinkAnim"/>
</DataTrigger.ExitActions>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>-
- darthmaule2
- Posts: 98
- Joined:
Re: Unable to animate a border's visibility or opacity
That is blinking the opacity of the children as well for me
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Unable to animate a border's visibility or opacity
Are you sure that the animation has Storyboard.TargetProperty="BorderBrush.Opacity"?
Who is online
Users browsing this forum: No registered users and 1 guest