Click here to Skip to main content
15,891,473 members
Articles / Web Development / ASP.NET

Windows Phone 7 View Model Style Video Player

,
Rate me:
Please Sign up or sign in to vote.
4.95/5 (82 votes)
14 Nov 2010CPOL72 min read 196.5K   3.9K   91  
A Designer/Developer collaboration in an example of a Windows Phone 7 View Model Style Video Player
// From:
// WPBehaviorsLibrary
// http://aimeegurl.com/2010/03/18/panoramic-navigation-on-windows-phone-7-with-no-code/
//
using System;
using System.Windows;
using System.Windows.Input;
using Microsoft.Expression.Interactivity;

using System.Windows.Interactivity;

namespace BehaviorsLibrary
{
  
        public class FlickGestureTrigger : TriggerBase<UIElement>
        {
            public FlickGestureTrigger() { 
            
            }
            public FlickDirection Direction
            {
                get { return (FlickDirection)GetValue(DirectionProperty); }
                set { SetValue(DirectionProperty, value); }
            }

            // Using a DependencyProperty as the backing store for Direction.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty DirectionProperty =
                DependencyProperty.Register("Direction", typeof(FlickDirection), typeof(FlickGestureTrigger), new PropertyMetadata(FlickDirection.Right));

            
            private UIElement AssociatedUIElement
            {
                get { return (UIElement)this.AssociatedObject; }
            }

            /// <summary>
            /// Attach the appropriate events.
            /// </summary>
            protected override void OnAttached()
            {
                base.OnAttached();
                this.AssociatedUIElement.ManipulationCompleted += new EventHandler<ManipulationCompletedEventArgs>(AssociatedUIElement_ManipulationCompleted);  
            }

            void AssociatedUIElement_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
            {
                if (e.IsInertial) {
                    var delta = e.TotalManipulation.Translation;
                    switch (Direction)
                    {
                        case FlickDirection.Up:
                            if (delta.Y > 0)
                                this.InvokeActions(e);
                            break;
                        case FlickDirection.Down:
                            if (delta.Y < 0)
                                this.InvokeActions(e);
                            break;
                        case FlickDirection.Left:
                            if (delta.X < 0)
                                this.InvokeActions(e);
                            break;
                        case FlickDirection.Right:
                            if (delta.X > 0)
                                this.InvokeActions(e);
                            break;
                        case FlickDirection.UpRight:
                            if (delta.Y > 0 && delta.X > 0)
                                this.InvokeActions(e);
                            break;
                        case FlickDirection.UpLeft:
                            if (delta.Y > 0 && delta.X < 0)
                                this.InvokeActions(e);
                            break;
                        case FlickDirection.DownRight:
                            if (delta.Y < 0 && delta.X > 0)
                                this.InvokeActions(e);
                            break;
                        case FlickDirection.DownLeft:
                            if (delta.Y < 0 && delta.X < 0)
                                this.InvokeActions(e);
                            break;
                        default:
                            break;
                    }
                }
            }


            /// <summary>
            /// Detach from the appropriate events.
            /// </summary>
            protected override void OnDetaching()
            {
                base.OnDetaching();

                this.AssociatedUIElement.ManipulationCompleted -= new EventHandler<ManipulationCompletedEventArgs>(AssociatedUIElement_ManipulationCompleted);  
          
            }



        }
        public enum FlickDirection
        { 
            Up, Down, Left, Right, UpRight, UpLeft, DownRight, DownLeft
        }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer (Senior) http://ADefWebserver.com
United States United States
Michael Washington is a Microsoft MVP. He is a ASP.NET and
C# programmer.
He is the founder of
AiHelpWebsite.com,
LightSwitchHelpWebsite.com, and
HoloLensHelpWebsite.com.

He has a son, Zachary and resides in Los Angeles with his wife Valerie.

He is the Author of:

Written By
User Interface Analyst
United Kingdom United Kingdom
I've been playing with computers since my first Acorn Electron, & after blowing up a few ZX Spectrums. I moved on to the C64 & Amiga, & eventually reluctantly on to the PC.

I have learnt a wide set of skills during my 38 years of existence, living in the UK, on the sunny south coast.

My main area of expertise is Graphic/Visual Design, Usability & UI Design. I am not a programmer, but am fairly technically minded due to studying Mechanical Engineering at Uni.

I have work both Freelance & for IBM as a Graphic Designer, & am skilled in the usual graphics packages like, PhotoShop, CorelDraw or Illustrator, Premier, Dreamweaver, Flash etc.
But I originally started with Lightwave & 3D animation.

Comments and Discussions