• 0

[WPF/C#] element Fade In, Move, Fade Out


Question

Hello gang,

I am playing around with WPF (if you seen the other posts, you know it's having a good time with me)

I need to load an item, in this case it's just an ellipse, have it fade in, move across the screen and then fade out. I am sure I am screwing it up... hence the question. In the example below the Move and Fade Out work, but the fade in does not. If I remark out the Fade out line the fade in works.


myStoryboard.Children.Add(animFadeOut);
[/CODE]

So... what dumb@$$ thing am I doing wrong?

[CODE]
private void button3_Click(object sender, RoutedEventArgs e)
{
TimeSpan ts = new TimeSpan(0, 0, 0, 12, 500);
StackPanel myStackPanel = new StackPanel();
myStackPanel.Margin = new Thickness(20);
Rectangle myRectangle = new Rectangle();
myRectangle.Name = "MyRectangle";
// Create a name scope for the page.
NameScope.SetNameScope(this, new NameScope());
this.RegisterName(myRectangle.Name, myRectangle);
myRectangle.Width = 100;
myRectangle.Height = 100;
SolidColorBrush mySolidColorBrush = new SolidColorBrush(Colors.Blue);
this.RegisterName("MySolidColorBrush", mySolidColorBrush);
myRectangle.Fill = mySolidColorBrush;
//FADE IN AMIMATION
DoubleAnimation animFadeIn = new DoubleAnimation();
animFadeIn.From = 0.0;
animFadeIn.To = 1.0;
animFadeIn.Duration = new Duration(new TimeSpan(0, 0, 0, 3, 400));
Storyboard.SetTargetName(animFadeIn, myRectangle.Name);
Storyboard.SetTargetProperty(animFadeIn, new PropertyPath(Rectangle.OpacityProperty));
//Y ANIMATION
Int16 iY = 10;
Int16 iX = 500;
TranslateTransform tt = new TranslateTransform(iX, iY);
DoubleAnimation animY = new DoubleAnimation(-(iX + myRectangle.Width), new Duration(ts));
tt.BeginAnimation(TranslateTransform.XProperty, animY);
myRectangle.RenderTransform = tt;

////FADE OUT ANIMATION
DoubleAnimation animFadeOut = new DoubleAnimation();
animFadeOut.From = 1.0;
animFadeOut.To = 0.0;
animFadeOut.Duration = new Duration(new TimeSpan(0, 0, 0, 15, 0));
Storyboard.SetTargetName(animFadeOut, myRectangle.Name);
Storyboard.SetTargetProperty(animFadeOut, new PropertyPath(Rectangle.OpacityProperty));

Storyboard myStoryboard = new Storyboard();
myStoryboard.Children.Add(animFadeIn);
myStoryboard.Children.Add(animFadeOut);
myStackPanel.Children.Add(myRectangle);
this.Content = myStackPanel;
myStoryboard.Begin(this);
}
[/CODE]

Link to comment
https://www.neowin.net/forum/topic/1054055-wpfc-element-fade-in-move-fade-out/
Share on other sites

1 answer to this question

Recommended Posts

This topic is now closed to further replies.
  • Posts

    • The one thing people should pirate is the operating system. You can't get rid of it...
    • "prepare for mandatory Windows 11 upgrade" This is apparently some new use of the word "mandatory" with which until now I was not acquainted. What's the consequence for non-compliance? Microsoft whining incessantly at you? Trump will levy a tariff on you? Oh wait, that's what they're doing now.
    • Waste of money. Most of Africa is a 14th century sewer. South Africa use to be wealthy & doing well until they "kicked out" the ones running it.
    • Adobe releases all-new Photoshop app for Android devices by Pradeep Viswanathan Early this year, Adobe released an all-new Photoshop app for iOS devices. Designed from the ground up for smartphones, the app allows users to easily add, remove, adjust, and combine content, as well as access free Adobe Stock assets to create new visuals. Today, Adobe announced a similar, brand-new Photoshop app for Android devices, currently in beta. It’s important to note that this Android version is not intended to replace the desktop version of Photoshop. Instead, it offers access to select powerful Photoshop features—including layering, masking, and the new Generative Fill—within an easy-to-use mobile interface. During the beta phase, the following features are available to all users: Following the beta phase, users will need a new Photoshop Mobile & Web plan to access the premium features. The premium features list includes the ability to remove objects by brushing over them with the Remove Tool, the ability to use Clone Stamp to hide unwanted objects by cloning areas of an image, the ability to fill portions of an image with content sampled from other parts of the image with Content-Aware Fill, the ability to export using additional file formats (PSD, TIF, JPG, PNG), and more. You can download the Adobe Photoshop app from the Google Play Store if your device is running Android 11 or later and has at least 6GB of RAM (8GB or more is recommended for optimal performance).
    • And what about all the toxic waste that "clean" nuclear energy produces?
  • Recent Achievements

    • Conversation Starter
      DarkShrunken earned a badge
      Conversation Starter
    • One Month Later
      jrromero17 earned a badge
      One Month Later
    • Week One Done
      jrromero17 earned a badge
      Week One Done
    • Conversation Starter
      johnwin1 earned a badge
      Conversation Starter
    • One Month Later
      Marwin earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      245
    2. 2
      snowy owl
      156
    3. 3
      ATLien_0
      142
    4. 4
      +FloatingFatMan
      138
    5. 5
      Xenon
      129
  • Tell a friend

    Love Neowin? Tell a friend!