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

  • Home
  • SEARCH
  • 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 976609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:46:26+00:00 2026-05-16T03:46:26+00:00

I want to begin a storyboard, every time my Image source changes. I have

  • 0

I want to begin a storyboard, every time my Image source changes.
I have implemented INotifyPropertyChanged.

Can anyone help me achieve this?

Thanks,

<Image Name="pic" HorizontalAlignment="Center" VerticalAlignment="Center" Source="{Binding ElementName=uc, Path=Image}">
        <Image.Resources>
            <Storyboard x:Key="picStory" x:Name="picStory">
                <DoubleAnimation 
                Storyboard.TargetProperty="(Image.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)"
                From="0" To="20" Duration="0:0:0.7" />
                <DoubleAnimation Storyboard.TargetProperty="(Image.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)" From="100" To="0" Duration="0:0:0.7" />
            </Storyboard>
        </Image.Resources>
        <Image.Style>
            <Style TargetType="{x:Type Image}" BasedOn="{StaticResource {x:Type Image}}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=Source}">
                        <DataTrigger.EnterActions>
                            <BeginStoryboard Storyboard="{StaticResource picStory}"/>
                        </DataTrigger.EnterActions>                            
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Image.Style>
        <Image.RenderTransform>
            <TransformGroup>
                <RotateTransform/>
                <TranslateTransform/>
            </TransformGroup>
        </Image.RenderTransform>  
    </Image>

Code bound to “uc”:

        private BitmapImage image;
        public BitmapImage Image
        {
            get { return image; }
            set
            {
                image = value;
                OnPropertyChanged("Image");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null) PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
  • 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-05-16T03:46:27+00:00Added an answer on May 16, 2026 at 3:46 am

    you can achieve this in another simple way by building a very basic custom control, which inherits from Image.

    Here the code for “MyImage”:

    public class MyImage : Image
    {
        public static readonly RoutedEvent ImageUpdatedEvent =
           EventManager.RegisterRoutedEvent("ImageUpdated", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MyImage));
    
        public event RoutedEventHandler ImageUpdated
        {
            add { this.AddHandler(ImageUpdatedEvent, value); }
            remove { this.RemoveHandler(ImageUpdatedEvent, value); }
        }
    
        public static readonly DependencyProperty MyImageSourceProperty = DependencyProperty.Register(
            "MyImageSource",
            typeof(ImageSource),
            typeof(MyImage),
            new PropertyMetadata(null, new PropertyChangedCallback(OnMyImageSourceChanged)));
    
        public ImageSource MyImageSource
        {
            get { return (ImageSource)GetValue(MyImageSourceProperty); }
            set
            {
                Source = value;
                SetValue(MyImageSourceProperty, value);
            }
        }
    
        private static void OnMyImageSourceChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            MyImage img = obj as MyImage;
            img.Source = args.NewValue as ImageSource;
            img.RaiseEvent(new RoutedEventArgs(ImageUpdatedEvent));
        }
    }
    

    The MyImage control has it’s own image source property and an own routed event called “ImageUpdated”, which will later cause the storyboard to be triggerd. I have simplified your image code:

    <Button Click="Button_Click" Grid.Row="0">Set Image through view model</Button>
    
        <local:MyImage Grid.Row="1"  x:Name="pic" MyImageSource="{Binding MySource}">
            <Image.Triggers>
                <EventTrigger RoutedEvent="local:MyImage.ImageUpdated">
                    <BeginStoryboard >
                        <Storyboard >
                            <DoubleAnimation Storyboard.TargetProperty="(Image.Opacity)" From="0" To="1" Duration="0:0:1" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Image.Triggers>
        </local:MyImage>
    

    The button sets a new value for the image source property of the bound viewmodel, which implements INotifyPropertyChanged:

     private void Button_Click(object sender, RoutedEventArgs e)
        {
            int randomValue = new Random(DateTime.Now.Second).Next(0, 2);
    
            if (randomValue == 0)
            {
                _viewModel.MySource = new BitmapImage(new Uri(@"test.bmp", UriKind.Relative));
            }
            else
            {
                _viewModel.MySource = new BitmapImage(new Uri(@"test2.bmp", UriKind.Relative));
            }
        }
    

    The setter in the viewmodel updates the MyImage with property changed pattern:

    public ImageSource MySource
        {
            get { return _mySource; }
            set
            {
                _mySource = value;
                RaisePropertyChanged("MySource");
            }
        }
    

    In my example, the opacity property is animated.

    Hope this was helpful

    Jan

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have chart in a canvas. when i click the chart i want it
i have a Storyboard in the MainWindow as follow : <Storyboard x:Key=OnMouseLeftButtonDown1> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=(UIElement.Opacity)
I just want to start an storyboard which makes an rectangle visible for 2
I am very new to wpf. I want to display an Image and a
I have an IQ test result which ranges from 40 to 180 and that
I have a method that enables me to animate objects that have to do
I want to animate the background of a border when the mouse is enters
I have a popup with UserControl inside. I need to hide this popup and
I am learning how to create animations with C#. so if I am animating
I use WPF with a ListView control. When a certain parameter is set to

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.