Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8994623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:28:27+00:00 2026-06-15T23:28:27+00:00

I have a ContentControl which has a Property Content . I wish to animate

  • 0

I have a ContentControl which has a Property Content. I wish to animate when the property content changes

Actual Senario

XAML

    <ContentControl Grid.Row="0" Content="{Binding Path=CurrentPage}">
                <ContentControl.Resources>
                    <DataTemplate DataType="{x:Type vm:SomeVM}">
                        <view:SomeView />
                    </DataTemplate>

                    <DataTemplate DataType="{x:Type vm:SomeOtherVM}">
                        <view:SomeOtherView />
                    </DataTemplate>
                </ContentControl.Resources>
     </ContentControl>  

Now I Wish to Fade Out the Current Content when the Property CurrentPages

Also id Possible Fade In in the New Page.

Value of CurrentPage can be any thing so i wish if that changes then the Tow animation Kick in…

Any help in this direction will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:28:28+00:00Added an answer on June 15, 2026 at 11:28 pm

    We use this attached behaviour

    public class AnimatedSwitch : DependencyObject
    {
        // Define the attached properties      
        public static DependencyProperty BindingProperty =
            DependencyProperty.RegisterAttached("Binding", typeof(object), typeof(AnimatedSwitch),
            new PropertyMetadata(BindingChanged));
    
        public static DependencyProperty PropertyProperty =
            DependencyProperty.RegisterAttached("Property", typeof(string), typeof(AnimatedSwitch));
    
        public static object GetBinding(DependencyObject e)
        {
            return e.GetValue(BindingProperty);
    
        }
    
        public static void SetBinding(DependencyObject e, object value)
        {
            e.SetValue(BindingProperty, value);
        }
    
        public static string GetProperty(DependencyObject e)
        {
            return (string)e.GetValue(PropertyProperty);
        }
    
        public static void SetProperty(DependencyObject e, string value)
        {
            e.SetValue(PropertyProperty, value);
        }
        // When the value changes do the fadeout-switch-fadein      
        private static void BindingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Storyboard fadeout = new Storyboard();
            var fadeoutAnim = new DoubleAnimation() { To = 0, Duration = new Duration(TimeSpan.FromSeconds(0.3)) };
            Storyboard.SetTarget(fadeoutAnim, d);
            Storyboard.SetTargetProperty(fadeoutAnim, new PropertyPath("Opacity"));
            fadeout.Children.Add(fadeoutAnim);
            fadeout.Completed += (d1, d2) =>
            {
                var propName = GetProperty(d);
                if (propName != null)
                {
                    var prop = d.GetType().GetProperty(propName);
                    var binding = GetBinding(d);
                    prop.SetValue(d, binding, null);
                }
                Storyboard fadein = new Storyboard();
                var fadeinAnim = new DoubleAnimation() { To = 1, Duration = new Duration(TimeSpan.FromSeconds(0.3)) };
                Storyboard.SetTarget(fadeinAnim, d);
                Storyboard.SetTargetProperty(fadeinAnim, new PropertyPath("Opacity"));
                fadein.Children.Add(fadeinAnim);
                fadein.Begin();
    
            };
            fadeout.Begin();
        }
    }
    

    Then

    <ContentControl Grid.Row="0"  
         yourNamespace:AnimatedSwitch.Binding="{Binding CurrentPage}"   
         yourNamespace:AnimatedSwitch.Property="Content">
                <ContentControl.Resources>
                    <DataTemplate DataType="{x:Type vm:SomeVM}">
                        <view:SomeView />
                    </DataTemplate>
    
                    <DataTemplate DataType="{x:Type vm:SomeOtherVM}">
                        <view:SomeOtherView />
                    </DataTemplate>
                </ContentControl.Resources>
     </ContentControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If i have a Binding which has a property path and the data source
I have a ContentControl , which I use the Content Property to place some
I have a view which contains a ContentControl which has its ContentTemplate changed dynamically
I have 2 Xaml files, one containing a DataTemplate which has a resource definition
I have a ContentControl and its content is a custom FrameworkElement. FrameworkElement has only
I suspect that the ContentControl which have a property of ContentTemplate is either a
I have a button defined in my XAML which has a button style and
I have an application that has a top level navigation menu which consists of
I have a parent contentcontrol which displays data via a datatemplate. The datatemplate contains
I have the following problem: I have a Button , which has a StackPanel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.