-
-
Notifications
You must be signed in to change notification settings - Fork 962
feat(controls): Make Durations customizable #1679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dkuaf
wants to merge
4
commits into
lepoco:main
Choose a base branch
from
dkuaf:feature/transitions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| // This Source Code Form is subject to the terms of the MIT License. | ||
| // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. | ||
| // Copyright (C) Leszek Pomianowski and WPF UI Contributors. | ||
| // All Rights Reserved. | ||
|
|
||
| using System.Windows.Markup; | ||
|
|
||
| namespace Wpf.Ui.Animations; | ||
|
|
||
| /// <summary> | ||
| /// A XAML markup extension that resolves an <see cref="AnimationDuration"/> key | ||
| /// to a concrete <see cref="Duration"/> value at parse time. | ||
| /// This allows Storyboard animations to reference configurable durations | ||
| /// without requiring <c>DynamicResource</c> (which cannot be frozen). | ||
| /// </summary> | ||
| /// <example> | ||
| /// <code lang="xml"> | ||
| /// <!-- Positional syntax --> | ||
| /// Duration="{markup:AnimationDuration Slow}" | ||
| /// | ||
| /// <!-- Named property syntax --> | ||
| /// Duration="{markup:AnimationDuration Duration=Slow}" | ||
| /// </code> | ||
| /// </example> | ||
| public class AnimationDurationExtension : MarkupExtension | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the <see cref="AnimationDuration"/> key to resolve. | ||
| /// </summary> | ||
| public AnimationDuration Duration { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AnimationDurationExtension"/> class. | ||
| /// </summary> | ||
| public AnimationDurationExtension() { } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AnimationDurationExtension"/> class. | ||
| /// </summary> | ||
| public AnimationDurationExtension(AnimationDuration animationDuration) | ||
| { | ||
| Duration = animationDuration; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns the <see cref="System.Windows.Duration"/> associated with the current | ||
| /// <see cref="Duration"/> key, including any user-defined override. | ||
| /// </summary> | ||
| public override object ProvideValue(IServiceProvider serviceProvider) | ||
| { | ||
| return AnimationDurationsDictionary.Get(Duration); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Defines the speed categories available for control animations. | ||
| /// Each key maps to a <see cref="Duration"/> value held in | ||
| /// <see cref="AnimationDurationsDictionary"/>. | ||
| /// </summary> | ||
| public enum AnimationDuration | ||
| { | ||
| /// <summary> | ||
| /// A longer duration intended for prominent or decorative transitions. | ||
| /// </summary> | ||
| SlowDuration, | ||
|
|
||
| /// <summary> | ||
| /// The standard duration for most interactive feedback animations. | ||
| /// </summary> | ||
| NormalDuration, | ||
|
|
||
| /// <summary> | ||
| /// A shorter duration for rapid state changes. | ||
| /// </summary> | ||
| FastDuration, | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A static registry that maps each <see cref="AnimationDuration"/> key to a | ||
| /// <see cref="Duration"/> value. Defaults are provided out of the box and can be | ||
| /// overridden at application startup via <see cref="Set"/> or through the | ||
| /// corresponding properties on <see cref="ControlsDictionary"/> | ||
| /// (e.g. <c><ui:ControlsDictionary SlowDuration="0:0:0.9" /></c>). | ||
| /// Overrides must be applied before the control dictionaries are loaded, | ||
| /// because <see cref="AnimationDurationExtension"/> resolves values at XAML parse time. | ||
| /// </summary> | ||
| public static class AnimationDurationsDictionary | ||
|
Check warning on line 87 in src/Wpf.Ui/Animations/AnimationDurationExtension.cs
|
||
| { | ||
| private static readonly Dictionary<AnimationDuration, Duration> Durations = new() | ||
| { | ||
| [AnimationDuration.SlowDuration] = new Duration(TimeSpan.FromMilliseconds(333)), | ||
| [AnimationDuration.NormalDuration] = new Duration(TimeSpan.FromMilliseconds(167)), | ||
| [AnimationDuration.FastDuration] = new Duration(TimeSpan.FromMilliseconds(80)), | ||
| }; | ||
|
|
||
| /// <summary> | ||
| /// Returns the <see cref="Duration"/> for the specified <paramref name="key"/>, | ||
| /// using the user-defined override if one exists, otherwise the built-in default. | ||
| /// </summary> | ||
| /// <param name="key">The animation speed category to look up.</param> | ||
| public static Duration Get(AnimationDuration key) | ||
| { | ||
| return Durations[key]; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Overrides the <see cref="Duration"/> for the specified <paramref name="key"/>. | ||
| /// Must be called before the WPF UI control dictionaries are parsed. | ||
| /// </summary> | ||
| /// <param name="key">The animation speed category to override.</param> | ||
| /// <param name="value">The desired duration.</param> | ||
| public static void Set(AnimationDuration key, TimeSpan value) | ||
| { | ||
| Durations[key] = new Duration(value); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's drop the
Durationfrom all, it's already anAnimationDuration.I also think we can also structure this differently to avoid the Dictionary and ControlsDictionary changes.
Something like