-
Recently Browsing 0 members
- No registered users viewing this page.
-
Similar Content
-
Microsoft updates official lightweight Windows 11 Validation OS with DISM, WPF .NET upgrades
By hellowalkman,
- microsoft
- windows 11
- (and 9 more)
- 0 replies
- 0 views
-
The head of Microsoft's Windows team wants your thoughts about UX frameworks
By John Callaham,
- microsoft
- microsoft windows
- (and 8 more)
- 20 replies
- 7 views
-
Microsoft may soon ditch DirectUI and move to XAML, WinAppSDK on next-gen Windows 11
By hellowalkman,
- windows 11 gallery
- windows 11 ui
- (and 17 more)
- 20 replies
- 8 views
-
Microsoft MSIX Packaging Tool for Windows apps gets major update with bunch of new features
By hellowalkman,
- msix packaging tool
- msix
- (and 8 more)
- 0 replies
- 5 views
-
Windows 10 WinRT API Pack lets developers add WinRT features to WPF and WinForms
By indospot,
- microsoft
- windows 10
- (and 5 more)
- 2 replies
- 2,574 views
-
Question
James Rose
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.
So... what dumb@$$ thing am I doing wrong?
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