TransitionPresenter.cs :  » Windows-Presentation-Foundation » Caliburn » ContactManager » Controls » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Windows Presentation Foundation » Caliburn 
Caliburn » ContactManager » Controls » TransitionPresenter.cs
namespace ContactManager.Controls{
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Markup;

    [ContentProperty("Content")]
    public class TransitionPresenter : Grid
    {
        public event EventHandler TransitionCompleted = delegate { };

        public static readonly DependencyProperty ContentProperty =
            DependencyProperty.Register(
                "Content",
                typeof(object),
                typeof(TransitionPresenter),
                new PropertyMetadata(ContentChanged)
                );

        public static readonly DependencyProperty ContentTemplateProperty =
            DependencyProperty.Register(
                "ContentTemplate",
                typeof(DataTemplate),
                typeof(TransitionPresenter),
                null
                );

        public static readonly DependencyProperty TransitionProperty =
            DependencyProperty.Register(
                "Transition",
                typeof(ITransition),
                typeof(TransitionPresenter),
                new PropertyMetadata(new CrossFade())
                );

        public object Content
        {
            get { return GetValue(ContentProperty) as UIElement; }
            set { SetValue(ContentProperty, value); }
        }

        public DataTemplate ContentTemplate
        {
            get { return GetValue(ContentTemplateProperty) as DataTemplate; }
            set { SetValue(ContentTemplateProperty, value); }
        }

        public ITransition Transition
        {
            get { return GetValue(TransitionProperty) as ITransition; }
            set { SetValue(TransitionProperty, value); }
        }

        private static void ContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var presenter = (TransitionPresenter)d;
            presenter.DoTransition(e.NewValue, new CrossFade());
        }

        public void DoTransition(object newContent, ITransition transition)
        {
            if(newContent == null)
            {
                Children.Clear();
                return;
            }

            UIElement view;

            if(ContentTemplate != null)
            {
                var template = ContentTemplate.LoadContent();
                var fe = template as FrameworkElement;

                if(fe != null)
                    fe.DataContext = newContent;

                view = template as UIElement;
            }
            else view = newContent as UIElement;

            if(view == null) return;

            if(Children.Count > 0)
            {
                if(transition.RequiresNewContentTopmost)
                {
                    Children.Add(view);
                    transition.BeginTransition(this, Children[0], view);
                }
                else
                {
                    Children.Insert(0, view);
                    transition.BeginTransition(this, Children[1], view);
                }
            }
            else
            {
                Children.Add(view);
                TransitionEnded(transition, null, view);
            }
        }

        public void TransitionEnded(ITransition transition, UIElement oldContent, UIElement newContent)
        {
            if(oldContent != null) Children.Remove(oldContent);
            TransitionCompleted(this, EventArgs.Empty);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.