Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to WPF and I'm not quite sure how to combine these two sections of code. My goal is to use a frame control to create an animation by adjusting the angle of the Frame control.
I'm using Visual Studio 2012 C#.


The code:
Part 1:
XML
<Frame x:Name="frame1" Width="200" Height="200" Background="LightPink" Canvas.Left="97" Canvas.Top="28">
            <Frame.BitmapEffect>
                <DropShadowBitmapEffect />
            </Frame.BitmapEffect>
            <Frame.LayoutTransform>
                <RotateTransform Angle="40" />
            </Frame.LayoutTransform>
</Frame>



Part 2:
XML
<Rectangle Name="myrect" Width="1" Height="1">
    <Rectangle.Fill>
        <SolidColorBrush Color="Red"/>
    </Rectangle.Fill>   
    <Rectangle.Triggers>
        <EventTrigger RoutedEvent="Window.Loaded">
            <BeginStoryboard>
                <Storyboard RepeatBehavior="Forever">
                    <DoubleAnimation Storyboard.TargetName="myrect" 
                       Storyboard.TargetProperty="Width" From="1" To="350" 
                       Duration="0:0:1" BeginTime="0:0:0"/>
                    <DoubleAnimation Storyboard.TargetName="myrect" 
                       Storyboard.TargetProperty="Height" From="1" To="250" 
                       Duration="0:0:1" BeginTime="0:0:1"/>
                    <DoubleAnimation Storyboard.TargetName="myrect" 
                       Storyboard.TargetProperty="Height" From="250" 
                       To="1" Duration="0:0:1" BeginTime="0:0:2"/>
                    <DoubleAnimation Storyboard.TargetName="myrect" 
                       Storyboard.TargetProperty="Width" From="350" To="1" 
                       Duration="0:0:1" BeginTime="0:0:3"/>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Rectangle.Triggers>
</Rectangle>


This is what I have so far:

XAML:
XML
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Custom="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon" x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <DockPanel HorizontalAlignment="Left" Height="29" LastChildFill="False" VerticalAlignment="Top" Width="517"/>
        <DockPanel HorizontalAlignment="Left" Height="291" LastChildFill="False" Margin="0,29,0,0" VerticalAlignment="Top" Width="140"/>
        <DockPanel Height="291" LastChildFill="False" Margin="140,29,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="377">
            <Frame Name="mainFrame" Content="Frame" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" DockPanel.Dock="Left" Width="377" Navigated="Frame_Navigated_1" Background="Black">
                <Frame.Triggers>
                    <EventTrigger RoutedEvent="mainFrame.Navigated">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="mainFrame" 
                       Storyboard.TargetProperty="Angle" From="1" To="300" 
                       Duration="0:0:1" BeginTime="0:0:0"/>
                                <DoubleAnimation Storyboard.TargetName="mainFrame" 
                       Storyboard.TargetProperty="Angle" From="300" To="250" 
                       Duration="0:0:1" BeginTime="0:0:1"/>
                                <DoubleAnimation Storyboard.TargetName="mainFrame" 
                       Storyboard.TargetProperty="Angle" From="250" 
                       To="350" Duration="0:0:1" BeginTime="0:0:2"/>
                                <DoubleAnimation Storyboard.TargetName="mainFrame" 
                       Storyboard.TargetProperty="Angle" From="350" To="1" 
                       Duration="0:0:1" BeginTime="0:0:3"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Frame.Triggers>
            </Frame>
        </DockPanel>
    </Grid>
</Window>

Code Behind:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Frame_Navigated_1(object sender, NavigationEventArgs e)
        {

        }
    }
}
Posted
Updated 7-Nov-12 17:16pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900