Control storyboard inside custom control...by code
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: Control storyboard inside custom control...by code

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Posts
    15

    Control storyboard inside custom control...by code

    Hello,
    How do I please control (start, stop, pause, go to specific time) a controltemplate storyboard inside a custom control..by code?

    The XAML:
    Code:
    <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':
    Code:
    Dim myStoryboard As New Storyboard
    myStoryboard = Arrow.FindResource("Storyboard1")
    myStoryboard.Begin()
    Code:
    Dim myStoryboard As New Storyboard
    myStoryboard = CType(Me.Resources("Storyboard1"), Storyboard)
    myStoryboard.Begin(Arrow)
    Code:
    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:
    Code:
    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 by Jayme65; May 24th, 2013 at 12:15 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center