wpf - Problem at the beginning of a ColorAnimation for a GradientStop in a VisualState -


I have a very strange problem with ColorAnimation What I want to do is very simple (I think): I have As a backdrop, there is a rectangle with a GradientBrush. There are different viewstats in this rectangle that change the color of the gradient. I want to insert an animation for transition between states. My problem is that when I change the state, the animation does not start with the current color, but with the default color

Here's a code snippet that can help you regenerate it: & lt; Window x: orbit = "testcoll animation. Window 1" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/comfx / 2006 / Xaml "title =" window1 "height =" 350 "width =" 525 "& gt; & Lt; Grid & gt; & Lt; Grid.RowDefinitions & gt; & Lt; Roadfinition /> & Lt; Roadfinion height = "30" /> & Lt; /Grid.RowDefinitions> & Lt; Grid.ColumnDefinitions & gt; & Lt; Column width = "*" /> & Lt; Column width = "*" /> & Lt; /Grid.ColumnDefinitions> & Lt; Rectangle grid. Rows = "0" grid. Column = "0" grid. Column = "2" x: name = "recapture" & gt; & Lt; VisualStateManager.VisualStateGroups & gt; & Lt; VisualStateGroup & gt; & Lt; VisualStateGroup.Transitions & gt; & Lt; VisualTransition generated period = "0: 0: 0.5" /> & Lt; /VisualStateGroup.Transitions> & Lt; VisualState X: Name = "OrangeState" & gt; & Lt; Storyboard & gt; & Lt; ColorAnimation Storyboard TargetProperty = "Color" Storyboard. TargetName = "stop1" To = "Orange" /> & Lt; / Storyboard & gt; & Lt; / VisualState & gt; & Lt; VisualState X: Name = "RedStat" & gt; & Lt; Storyboard & gt; & Lt; Color animation storyboard Targetproperty = "color" storyboard Goal name = "stop 1" per "red" /> & Lt; / Storyboard & gt; & Lt; / VisualState & gt; & Lt; / VisualStateGroup & gt; & Lt; /VisualStateManager.VisualStateGroups> & Lt; Rectangle.Fill & gt; & Lt; LinearGradientBrush EndPoint = "0.5,1" Start Page = "0.5,0" & gt; & Lt; GradientStop x: name = "stop1" color = "lightgray" offset = "0" /> & Lt; GradientStop x: name = "stop2" color = "lightgray" offset = "1" /> & Lt; / LinearGradientBrush & gt; & Lt; /Rectangle.Fill> & Lt; / Rectangles & gt; & Lt; Button grid Rows = "1" grid. Column = "0" content = "go to orange" x: name = "orange button" click = "orange button button" /> & lt; Button grid Roll = "1" grid. Column = "1" content = "go to red" x: name = "redboot" click = "redboot_click" /> & Lt; / Grid & gt; & Lt; / Window & gt;

Event handlers just call for state change:

  Private Zero Orange button (Object Sender, Routing, and Eggy E) {VisualStateManager.GoToElementState ( This, "OrangeState", true); } Private Zero redButton_Click (Object Sender, RoutedEventArgs e) {VisualStateManager.GoToElementState (this., "RedState", is true); }   

In this case, if I go to the orange state, the animation goes from gray to orange. But again, when I go to red state, the animation turns red from gray. I would like to go from orange to red (and hopefully).

I have tried to use more code instead of SolarColorBrush instead of LinearGradientBrush I'm getting the desired form of the storyboard to VisualStates < I tried to use / code> (but with LinearGradientBrush ) and it works as expected only in this situation I have re-published this issue: LinearGradientBrush and ColorAnimation in a VisualState . P> Am I doing something wrong? What should I possibly do?

If you change the target directly into GradientStop color then working on animating linear grids will: < / P>

  & lt; VisualState X: Name = "OrangeState" & gt; & Lt; Storyboard & gt; & Lt; ColorAnimation Storyboard TargetProperty = "(Rectangle.Fill). (LinearGradientBrush.GradientStops) [0]. (GradientStop.Color)" Storyboard.TargetName = "rect" To = "Orange" /> & Lt; / Storyboard & gt; & Lt; / VisualState & gt; & Lt; VisualState X: Name = "RedStat" & gt; & Lt; Storyboard & gt; & Lt; ColorAnimation Storyboard TargetProperty = "(Rectangle.Fill). (LinearGradientBrush.GradientStops) [0]. (GradientStop.Color)" Storyboard.TargetName = "rect" To = "Red" /> & Lt; / Storyboard & gt; & Lt; / VisualState & gt;    

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -