Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF
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:
<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:
<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:
<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:
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 7-Nov-12 16:16pm
shelby672.5K
Edited 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)



Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100