feat(controls): Make Durations customizable#1679
Open
dkuaf wants to merge 4 commits intolepoco:mainfrom
Open
Conversation
Contributor
Author
|
@pomianowski yo! do you think this feature should be added? if yes, i was thinking about this and i think just 3 static TimeSpan properties should be fine instead of AnimationDurationExtension.cs |
Nuklon
reviewed
Apr 28, 2026
| /// <summary> | ||
| /// A longer duration intended for prominent or decorative transitions. | ||
| /// </summary> | ||
| SlowDuration, |
Collaborator
There was a problem hiding this comment.
Let's drop the Duration from all, it's already an AnimationDuration.
I also think we can also structure this differently to avoid the Dictionary and ControlsDictionary changes.
Something like
// 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>
/// 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(AnimationDurationType animationDurationType)
{
Duration = AnimationDuration.FromType(animationDurationType);
}
/// <summary>
/// Gets or sets the <see cref="AnimationDuration" /> key to resolve.
/// </summary>
public AnimationDuration Duration { get; set; }
/// <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 Duration.Duration;
}
}
public struct AnimationDuration
{
private static readonly AnimationDuration[] _durations =
[
new() { Duration = TimeSpan.FromMilliseconds(333), Type = AnimationDurationType.Slow },
new() { Duration = TimeSpan.FromMilliseconds(167), Type = AnimationDurationType.Normal },
new() { Duration = TimeSpan.FromMilliseconds(80), Type = AnimationDurationType.Fast }
];
public Duration Duration { get; set; }
public AnimationDurationType Type { get; set; }
public static AnimationDuration Normal
{
get => _durations[1];
set => _durations[1] = value;
}
public static AnimationDuration Fast
{
get => _durations[2];
set => _durations[2] = value;
}
public static AnimationDuration Slow
{
get => _durations[0];
set => _durations[0] = value;
}
public static AnimationDuration FromType(AnimationDurationType type) => _durations[(int)type];
}
/// <summary>
/// Defines the duration types available for control animations.
/// </summary>
public enum AnimationDurationType
{
/// <summary>
/// A longer duration intended for prominent or decorative transitions.
/// </summary>
Slow,
/// <summary>
/// The standard duration for most interactive feedback animations.
/// </summary>
Normal,
/// <summary>
/// A shorter duration for rapid state changes.
/// </summary>
Fast,
}
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Durations on Animations are freezable, this pull request provides a way to make Durations customizable.
Pull request type
Please check the type of change your PR introduces:
What is the current behavior?
Durations on Animation has hard coded values for all controls
Issue Number: #1586
fixes #1586
What is the new behavior?
Durations can be of three types: SlowDuration, NormalDuration and FastDuration. These can all be set when merging ControlsDictionary. Defaults to previous hardcoded values (no breaking change)
<ui:ControlsDictionary SlowDuration="0:0:0.0" NormalDuration="0:0:0.0" FastDuration="0:0:0.0" />Other information