Hello,
How do I please control (start, stop, pause, go to specific time) a controltemplate storyboard inside a custom control..by code?
The XAML:
In these 3 attemps, the debugger complains about not being able to resolve 'rectangle':
With this one, I can verify that neither the template is not found:
Please help!! ;-)
How do I please control (start, stop, pause, go to specific time) a controltemplate storyboard inside a custom control..by code?
The XAML:
VB.NET:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="Window6"
Title="MainWindow" Height="394" Width="324">
<Window.Resources>
<!-- ********** Button template **********-->
<Style x:Key="Arrow" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}" x:Name="CTarrow">
<ControlTemplate.Resources>
<Storyboard x:Key="Storyboard1" RepeatBehavior="Forever" AutoReverse="True">
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
<DiscreteColorKeyFrame KeyTime="0" Value="#FF0080FF"/>
<DiscreteColorKeyFrame KeyTime="0:0:0.5" Value="#FF004D99"/>
<DiscreteColorKeyFrame KeyTime="0:0:0.8" Value="#FF0080FF"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Grid>
<ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Rectangle x:Name="rectangle" Height="30" Width="50" Fill="Black" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Button HorizontalAlignment="Left" VerticalAlignment="Top" Style="{DynamicResource Arrow}" x:Name="Arrow" />
</Grid>
</Window>
In these 3 attemps, the debugger complains about not being able to resolve 'rectangle':
VB.NET:
Dim myStoryboard As New Storyboard
myStoryboard = Arrow.FindResource("Storyboard1")
myStoryboard.Begin()
VB.NET:
Dim myStoryboard As New Storyboard
myStoryboard = CType(Me.Resources("Storyboard1"), Storyboard)
myStoryboard.Begin(Arrow)
VB.NET:
Dim myStoryboard As Storyboard = TryCast(Arrow.Template.Resources("Storyboard1"), Storyboard)
If myStoryboard IsNot Nothing Then
myStoryboard.Begin(Arrow)
End If
With this one, I can verify that neither the template is not found:
VB.NET:
Dim ct As ControlTemplate = TryCast(Me.FindName("CTarrow"), ControlTemplate)
If ct IsNot Nothing Then
Debug.Print("ControlTemplate found")
Dim sb As Storyboard = TryCast(ct.Resources("Storyboard1"), Storyboard)
If sb IsNot Nothing Then
sb.Begin()
Debug.Print("Storyboard found")
End If
End If
Please help!! ;-)
Last edited: