Xavalon / XamlStyler

Visual Studio extension to help format your XAML source code
Apache License 2.0
1.2k stars 129 forks source link

Add option to convert ObjectAnimationUsingKeyFrame to Setters #49

Open grochocki opened 8 years ago

grochocki commented 8 years ago

Visual State Manager Setters were introduced for UWPs in Windows 10:

If you are going to use animation to change the state you can continue to use old approach with Storyboard but in many cases animation is not needed. For example if you want to change your layout because user changed screen orientation, you need to change properties of controls very quickly. So, developers usually used ObjectAnimationUsingKeyFrame in order to make all needed changes in 0 seconds:

<Storyboard>
 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
 <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
 </ObjectAnimationUsingKeyFrames>
</Storyboard>

You can see that this approach is not optimal because it requires using several complex objects with many parameters to make the simple thing. That’s why a new XAML element called Setter can be very useful. For example, you can rewrite the same thing using the Setter element:

<VisualState.Setters>
 <Setter Target="comboBox.Visibility" Value="Collapsed"></Setter>
</VisualState.Setters>

It’s much clearer. Developers need to declare a property’s name and a new value in the selected state.

Adding an option to optionally convert ObjectAnimationUsingKeyFrames to Setters would greatly clean up Visual State Manager code.

grochocki commented 4 years ago

This would be a great feature, but a couple open questions based on my initial attempt: