I tried this again on my new x64 machine and the animation was running smoothly without any issues. What I was seeing earlier must have been related to poor performance on my old machine.
Up vote 0 down vote favorite share g+ share fb share tw.
I was playing around with storyboards, a flipping animation, and visual brushes. I have encountered an issue though. Below is the xaml and code-behind of a small sample I quickly put together to try to demonstrate the problem.
When you first start the app, you are presented with a red square and two buttons. If you click the "Flip" button, the red square will "flip" over and a blue one will appear. In reality, all that is happening is that the scale of the width of the StackPanel that the red square is in is being decreased until it reaches zero and then the StackPanel where a blue square is, whose width is initially scaled to zero, has its width increased.
If you click the "Flip" button a few times, the animation looks ok and smooth. Now, if you hit the "Reflection" button, a reflection of the red/blue buttons is added to their respective StackPanels. Hitting the "Flip" button now will still cause the flip animation but it is no longer a smooth animation.
The StackPanels width often does not shrink to zero. The width shrinks somewhat but then just stops before being completely invisible. Then the other StackPanel appears as usual.
The only thing that changed was adding the reflection, which is just a VisualBrush. Below is the code. Does anyone have any idea why the animations are different between the two cases (stalling in the second case)?
Thanks. Flip Reflection Here are the button click handlers: using System; using System.Collections. Generic; using System.
Linq; using System. Text; using System. Windows; using System.Windows.
Controls; using System.Windows. Data; using System.Windows. Documents; using System.Windows.
Input; using System.Windows. Media; using System.Windows.Media. Imaging; using System.Windows.
Navigation; using System.Windows. Shapes; using System.Windows.Media. Animation; namespace WpfFlipTest { public partial class Window1 : Window { public Window1() { InitializeComponent(); } bool flipped = false; private void FlipButton_Click(object sender, RoutedEventArgs e) { Storyboard sbFlip = (Storyboard)Resources"sbFlip"; Storyboard sbFlipBack = (Storyboard)Resources"sbFlipBack"; if (flipped) { sbFlipBack.Begin(); flipped = false; } else { sbFlip.Begin(); flipped = true; } } bool reflection = false; private void ReflectionButton_Click(object sender, RoutedEventArgs e) { if (reflection) { reflection = false; redRefelction.
Visibility = Visibility. Collapsed; blueRefelction. Visibility = Visibility.
Collapsed; } else { reflection = true; redRefelction. Visibility = Visibility. Visible; blueRefelction.
Visibility = Visibility. Visible; } } } } UPDATE: I have been testing this some more to try to find out what is causing the issue I am seeing and I believe I found what is causing the issue. Below I have pasted new xaml and code-behind.
The new sample below is very similar to the original sample, with a few minor modifications. The xaml basically consists of two stack panels, each containing two borders. The second border in each stack panel is a visual brush (a reflection of the border above it).
Now, when I click the "Flip" button, one stack panel gets its ScaleX reduced to zero, while the second stack panel, whose initial ScaleX is zero, gets its ScaleX increased to 1. This animation gives the illusion of flipping. There are also two textblocks which display the scale factor of each stack panel.
I added those to try to diagnose my issue. The issue is (as described in the oringal post) that the flipping animation is not smooth. Every time I hit the flip button, the animation starts but whenever the ScaleX factor gets to around .14 to .16, the animation looks like it stalls and the stack panels never have there ScaleX reduced to zero, so they never totally disappear.
Now, the strange thing is that if I change the Width/Height properties of the "frontBorder" and "backBorder" borders defined below to use explict values instead of Auto, such as Width=105 and Height=75 (to match the button in the border) everything works fine. The animation stutters the first two or three times I run it but after that the flips are smooth and flawless. (BTW, when an animation is run for the first time, is there something going on in the background, some sort of initialization, that causes it to be a little slow the first time?
) Is it possible that the Auto Width/Height of the borders are causing the issue? I can reproduce it everytime but I am not sure why Auto Width/Height would be a problem. Below is the sample.
Thanks for the help. Flip Code-behind: using System; using System.Collections. Generic; using System.
Linq; using System. Text; using System. Windows; using System.Windows.
Controls; using System.Windows. Data; using System.Windows. Documents; using System.Windows.
Input; using System.Windows. Media; using System.Windows.Media. Imaging; using System.Windows.
Navigation; using System.Windows. Shapes; using System.Windows.Media. Animation; namespace FlipTest { /// /// Interaction logic for Window1.
Xaml /// public partial class Window1 : Window { public Window1() { InitializeComponent(); } bool flipped = false; private void FlipButton_Click(object sender, RoutedEventArgs e) { Storyboard sbFlip = (Storyboard)Resources"sbFlip"; Storyboard sbFlipBack = (Storyboard)Resources"sbFlipBack"; if (flipped) { sbFlipBack.Begin(); flipped = false; } else { sbFlip.Begin(); flipped = true; } } } } c# wpf animation storyboard link|improve this question edited Sep 16 '11 at 23:59Dave Clemmer1,78331030 asked Jan 21 '10 at 15:21Flack875525 99% accept rate.
I've run this a couple of times and it's working as you would expect. The animation is smooth even with the reflection on - are you running on a 386? :) – PaulB Jan 27 '10 at 12:45.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.