`
jiasongmao
  • 浏览: 648996 次
  • 性别: Icon_minigender_1
  • 来自: 石家庄
社区版块
存档分类
最新评论

silverlight翻转代码

阅读更多
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace slapp002
{
    public enum enumDirection { Up, Down, Left, Right };
    public class cShow3DPlane
    {
        public cShow3DPlane()
        {
            m_IsMoveOverIn = true;
            m_IsMoveOverOut = true;
            m_MoveSpeed = 2;
            sbTimeIn = new Storyboard();
            sbTimeOut = new Storyboard();
            SetTime(10, 10);
            sbTimeIn.Completed += new EventHandler(sbTimeIn_Completed);
            sbTimeOut.Completed += new EventHandler(sbTimeOut_Completed);
        }

        private int m_TimeSpeed1, m_TimeSpeed2, m_MoveSpeed, m_PlaneSpeed, m_InEnd, m_OutEnd;
        private double m_InLocalZ, m_OutLocalZ;
        private PlaneProjection m_pInPlane, m_pOutPlane;
        private Storyboard sbTimeIn, sbTimeOut;
        private enumDirection m_Direction;
        private bool m_IsMoveOverIn, m_IsMoveOverOut;
        //根据方向初始化两个planeProjection的相关值        
        private void InitPlaneData()
        {
            m_pInPlane.RotationX = 0;
            m_pInPlane.RotationY = 0;
            m_pInPlane.RotationZ = 0;
            m_pInPlane.CenterOfRotationX = 0.5;
            m_pInPlane.CenterOfRotationY = 0.5;
            m_pInPlane.CenterOfRotationZ = 0;
            m_pOutPlane.RotationX = 0;
            m_pOutPlane.RotationY = 0;
            m_pOutPlane.RotationZ = 0;
            m_pOutPlane.CenterOfRotationX = 0.5;
            m_pOutPlane.CenterOfRotationY = 0.5;
            m_pOutPlane.CenterOfRotationZ = 0;
            m_pOutPlane.LocalOffsetZ = m_OutLocalZ;
            m_pOutPlane.GlobalOffsetZ = -m_OutLocalZ;
            m_pInPlane.LocalOffsetZ = m_InLocalZ;
            m_pInPlane.GlobalOffsetZ = -m_InLocalZ;
            switch (m_Direction)
            {
                case enumDirection.Up:
                    m_pInPlane.RotationX = -90;
                    m_InEnd = 0;
                    m_pOutPlane.RotationX = 0;
                    m_OutEnd = 90;
                    m_PlaneSpeed = m_MoveSpeed;
                    break;
                case enumDirection.Down:
                    m_pInPlane.RotationX = 90;
                    m_InEnd = 0;
                    m_pOutPlane.RotationX = 0;
                    m_OutEnd = -90;
                    m_PlaneSpeed = -m_MoveSpeed;
                    break;
                case enumDirection.Left:
                    m_pInPlane.RotationY = 90;
                    m_InEnd = 0;
                    m_pOutPlane.RotationY = 0;
                    m_OutEnd = -90;
                    m_PlaneSpeed = -m_MoveSpeed;
                    break;
                case enumDirection.Right:
                    m_pInPlane.RotationY = -90;
                    m_InEnd = 0;
                    m_pOutPlane.RotationY = 0;
                    m_OutEnd = 90;
                    m_PlaneSpeed = m_MoveSpeed;
                    break;
            }
        }

        public void Begin()
        {
            m_IsMoveOverIn = false;
            m_IsMoveOverOut = false;
            sbTimeIn.Begin();
            sbTimeOut.Begin();
        }

        //设置进入和离开对象        
        public void SetInOutPlane(Grid gridIn, Grid gridOut, enumDirection eDirection)
        {
            m_pInPlane = new PlaneProjection();
            m_pOutPlane = new PlaneProjection();
            gridIn.Projection = m_pInPlane;
            gridOut.Projection = m_pOutPlane;
            if (eDirection == enumDirection.Left || eDirection == enumDirection.Right)
            {
                m_InLocalZ = gridIn.ActualWidth / 2;
                m_OutLocalZ = gridOut.ActualWidth / 2;
            }
            else
            {
                m_InLocalZ = gridIn.ActualHeight / 2;
                m_OutLocalZ = gridOut.ActualHeight / 2;
            }
            m_Direction = eDirection;
            InitPlaneData();
        }

        //重载       
        public void SetInOutPlane(System.Windows.Controls.Control controlIn, System.Windows.Controls.Control controlOut, enumDirection eDirection)
        {
            m_pInPlane = new PlaneProjection();
            m_pOutPlane = new PlaneProjection();
            controlIn.Projection = m_pInPlane;
            controlOut.Projection = m_pOutPlane;
            if (eDirection == enumDirection.Left || eDirection == enumDirection.Right)
            {
                m_InLocalZ = controlIn.ActualWidth / 2;
                m_OutLocalZ = controlOut.ActualWidth / 2;
            }
            else
            {
                m_InLocalZ = controlIn.ActualHeight / 2;
                m_OutLocalZ = controlOut.ActualHeight / 2;
            }
            m_Direction = eDirection;
            InitPlaneData();
        }

        public bool MoveOver()
        {
            if (!m_IsMoveOverIn || !m_IsMoveOverOut)
                return false;
            else return true;
        }

        //设置进入和离开动画的速度   
        public void SetTime(int timeSpeed1, int timeSpeed2)
        {
            m_TimeSpeed1 = timeSpeed1;
            m_TimeSpeed2 = timeSpeed2;
            sbTimeIn.Duration = new Duration(TimeSpan.FromMilliseconds(m_TimeSpeed1));
            sbTimeOut.Duration = new Duration(TimeSpan.FromMilliseconds(m_TimeSpeed2));
        }

        //离开对象的动画     
        void sbTimeOut_Completed(object sender, EventArgs e)
        {
            //throw new NotImplementedException();          
            if (m_Direction == enumDirection.Left || m_Direction == enumDirection.Right)
            {
                m_pOutPlane.RotationY += m_PlaneSpeed;
                if (m_pOutPlane.RotationY == m_OutEnd) m_IsMoveOverOut = true;
            }
            if (m_Direction == enumDirection.Up || m_Direction == enumDirection.Down)
            {
                m_pOutPlane.RotationX += m_PlaneSpeed;
                if (m_pOutPlane.RotationX == m_OutEnd) m_IsMoveOverOut = true;
            }
            if (!m_IsMoveOverOut) sbTimeOut.Begin();
            else
            {
                m_pOutPlane.LocalOffsetZ = 0;
                m_pOutPlane.GlobalOffsetZ = 0;
            }
        }

        //进入对象的动画     
        void sbTimeIn_Completed(object sender, EventArgs e)
        {
            //throw new NotImplementedException();     
            if (m_Direction == enumDirection.Left || m_Direction == enumDirection.Right)
            {
                m_pInPlane.RotationY += m_PlaneSpeed;
                if (m_pInPlane.RotationY == m_InEnd) m_IsMoveOverIn = true;
            }
            if (m_Direction == enumDirection.Up || m_Direction == enumDirection.Down)
            {
                m_pInPlane.RotationX += m_PlaneSpeed;
                if (m_pInPlane.RotationX == m_InEnd) m_IsMoveOverIn = true;
            }
            if (!m_IsMoveOverIn) sbTimeIn.Begin();
            else
            {
                m_pInPlane.LocalOffsetZ = 0;
                m_pInPlane.GlobalOffsetZ = 0;
            }
        }
    }

}

 

 

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.DataVisualization.Charting;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace slapp002
{
	public partial class MainPage : UserControl
	{
        private cShow3DPlane c3d = new cShow3DPlane();
        private Grid gridCur = new Grid();
		public MainPage()
		{
			// Required to initialize variables
			InitializeComponent();

		}

		private void rightbt_Click(object sender, System.Windows.RoutedEventArgs e)
		{
            if (c3d.MoveOver())
            {
                c3d.SetInOutPlane(linechart, colchart, enumDirection.Right);
                //gridCur = gridUp;
                c3d.Begin();
            }

		}

		private void upbt_Click(object sender, System.Windows.RoutedEventArgs e)
		{
            if (c3d.MoveOver())
            {
                c3d.SetInOutPlane(linechart, colchart, enumDirection.Up);
                //gridCur = gridUp;
                c3d.Begin();
            }
		}

		private void leftbt_Click(object sender, System.Windows.RoutedEventArgs e)
		{
            if (c3d.MoveOver())
            {
                c3d.SetInOutPlane(linechart, colchart, enumDirection.Left);
                //gridCur = gridUp;
                c3d.Begin();
            }
        }

		private void downbt_Click(object sender, System.Windows.RoutedEventArgs e)
		{
            if (c3d.MoveOver())
            {
                c3d.SetInOutPlane(linechart, colchart, enumDirection.Down);
                //gridCur = gridUp;
                c3d.Begin();
            }
        }

		private void UserControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
		{
			

		}
	}
}

 

 

<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:slapp002_Control="clr-namespace:slapp002.Control" xmlns:local="clr-namespace:slapp002" mc:Ignorable="d"
	x:Class="slapp002.MainPage"
	Width="640" Height="480" Loaded="UserControl_Loaded">

	<Grid x:Name="LayoutRoot" Background="White" >
		<Grid.RowDefinitions>
			<RowDefinition Height="0.152*"/>
			<RowDefinition Height="0.848*"/>
		</Grid.RowDefinitions>
		<Button Content="上" x:Name="upbt" Height="26" Margin="265,8,289,0" VerticalAlignment="Top" Click="upbt_Click"/>
		<Button Content="左" x:Name="leftbt" Margin="162,29,0,18" HorizontalAlignment="Left" Width="86" Click="leftbt_Click"/>
		<Button Content="右" x:Name="rightbt" Margin="0,29,163,18" HorizontalAlignment="Right" Width="86" Click="rightbt_Click"/>
		<Button Content="下" x:Name="downbt" Margin="265,0,289,0" Height="26" VerticalAlignment="Bottom" Click="downbt_Click"/>
		
		<slapp002_Control:ColumnChartControl Name="colchart" Margin="0,0,0,0" Grid.Row="1"/>
		
		<local:LineChartControl Margin="0" Name="linechart" Grid.Row="1"/>
		
	</Grid>
</UserControl>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics