Click here to Skip to main content
15,569,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm employing the FluidKit.dll into my application to get a nice slide in/out transition effect for my windows, pages and usercontrols. Now I have it working, however it seems that the animations start getting a little jerky when there is more information on a transitioning page. I've read a little and it seems that I can aid in the fluidity of the transitions by implementing the RenderTargetBitmap functionality in my content presenter.

Does anyone know how to do this or have a good pointer for me? Below is the code I'm using for the ContentPresenter:




C#
public class NavigationPresenter : ContentPresenter
    {
        private readonly ContentPresenter oldContentPresenter;
        private readonly ContentPresenter newContentPresenter;
        private readonly TransitionPresenter transitionPresenter;
        private bool loaded;

        #region GoForward
        /// <summary>
        /// GoForward Dependency Property
        /// </summary>
        public static readonly DependencyProperty GoForwardProperty;

        /// <summary>
        /// Gets or sets the GoForward property
        /// </summary>
        public bool GoForward
        {
            get { return (bool)GetValue(GoForwardProperty); }
            set { SetValue(GoForwardProperty, value); }
        }
        #endregion

        #region Transition
        /// <summary>
        /// Transition Dependency Property
        /// </summary>
        public static readonly DependencyProperty TransitionProperty;

        /// <summary>
        /// Gets or sets the Transition property
        /// </summary>
        public Transition Transition
        {
            get { return (Transition)GetValue(TransitionProperty); }
            set { SetValue(TransitionProperty, value); }
        }
        #endregion

        internal UIElementCollection Children
        {
            get;
            private set;
        }

        static NavigationPresenter()
        {
            GoForwardProperty = DependencyProperty.Register(
                "GoForward",
                typeof(bool),
                typeof(NavigationPresenter),
                new FrameworkPropertyMetadata(false));

            TransitionProperty = DependencyProperty.Register(
                "Transition",
                typeof(Transition),
                typeof(NavigationPresenter),
                new FrameworkPropertyMetadata(new NavigationCubeTransition(), new PropertyChangedCallback(OnTransitionChanged)));

            ContentProperty.OverrideMetadata(
                typeof(NavigationPresenter),
                new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnContentValueChanged)));
        }

        public NavigationPresenter()
        {
            this.oldContentPresenter = new ContentPresenter();
            this.newContentPresenter = new ContentPresenter();

            this.transitionPresenter = new TransitionPresenter();
            this.transitionPresenter.Items.Add(this.oldContentPresenter);
            this.transitionPresenter.Items.Add(this.newContentPresenter);

            this.Children = new UIElementCollection(this, null);
            this.Children.Add(this.transitionPresenter);

            this.Loaded += (s, e) => this.loaded = true;
        }

        private static void OnTransitionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((NavigationPresenter)d).OnTransitionChanged(e);
        }

        private static void OnContentValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((NavigationPresenter)d).OnContentValueChanged(e);
        }

        private void OnContentValueChanged(DependencyPropertyChangedEventArgs e)
        {
            // switch ContentPresenters



            this.oldContentPresenter.Content = e.OldValue;
            this.newContentPresenter.Content = e.NewValue;

            if (this.loaded)
            {
                // if the transition supports the INavigationAware interface
                // prepare it using the GoForward/GoBackward methods
                if (this.transitionPresenter.Transition is INavigationAware)
                {
                    if (this.GoForward)
                        ((INavigationAware)this.transitionPresenter.Transition).GoForward();
                    else
                        ((INavigationAware)this.transitionPresenter.Transition).GoBackward();
                }

                // run the transition
                this.transitionPresenter.ApplyTransition(this.oldContentPresenter, this.newContentPresenter);
            }
        }

        private void OnTransitionChanged(DependencyPropertyChangedEventArgs e)
        {
            this.transitionPresenter.Transition = e.NewValue as Transition;
        }

        //TODO: try converting to RenderTargetBitmap
        protected override Visual GetVisualChild(int index)
        {
            if ((index < 0) || (index >= this.Children.Count))
                throw new ArgumentOutOfRangeException("index");

            return this.Children[index];
        }


        protected override int VisualChildrenCount
        {
            get
            {
                if (this.Children != null)
                    return this.Children.Count;
                else
                    return 0;
            }
        }
    }

I may be completely misunderstanding the implementation of RenderTargetBitmap, so if it's not the ContentPresenter that should utilize it then where would be best? Or if you have any better recommendations then that's great.



Kind regards,

Jib
Posted
Comments
davidcole 5-Feb-14 10:54am    
Did you ever solved this problem? Approach looks promising.

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