Skip to content

Commit

Permalink
Add automation peer for ProgressRing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Apr 4, 2020
1 parent 4548ebb commit 261560f
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 15 deletions.
Expand Up @@ -26,7 +26,7 @@ public override object GetPattern(PatternInterface patternInterface)

protected override string GetClassNameCore()
{
return typeof(DropDownButton).FullName;
return nameof(DropDownButton);
}

private DropDownButton GetImpl()
Expand Down
2 changes: 1 addition & 1 deletion ModernWpf.Controls/NumberBox/NumberBoxAutomationPeer.cs
Expand Up @@ -26,7 +26,7 @@ public override object GetPattern(PatternInterface patternInterface)

protected override string GetClassNameCore()
{
return typeof(NumberBox).FullName;
return nameof(NumberBox);
}

protected override string GetNameCore()
Expand Down
Expand Up @@ -19,7 +19,7 @@ protected override AutomationControlType GetAutomationControlTypeCore()

protected override string GetClassNameCore()
{
return typeof(PersonPicture).FullName;
return nameof(PersonPicture);
}
}
}
22 changes: 14 additions & 8 deletions ModernWpf.Controls/ProgressRing/ProgressRing.cs
@@ -1,7 +1,9 @@
using ModernWpf.Controls.Primitives;
using System;
using System;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using ModernWpf.Automation.Peers;
using ModernWpf.Controls.Primitives;

namespace ModernWpf.Controls
{
Expand All @@ -21,15 +23,19 @@ public class ProgressRing : Control

static ProgressRing()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ProgressRing),
new FrameworkPropertyMetadata(typeof(ProgressRing)));
DefaultStyleKeyProperty.OverrideMetadata(typeof(ProgressRing), new FrameworkPropertyMetadata(typeof(ProgressRing)));
}

public ProgressRing()
{
TemplateSettings = new ProgressRingTemplateSettings();
}

protected override AutomationPeer OnCreateAutomationPeer()
{
return new ProgressRingAutomationPeer(this);
}

#region IsActive

public bool IsActive
Expand All @@ -47,7 +53,7 @@ public bool IsActive

private static void OnIsActiveChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((ProgressRing)d).UpdateVisualStates(true);
((ProgressRing)d).ChangeVisualState(true);
}

#endregion
Expand All @@ -58,7 +64,7 @@ public override void OnApplyTemplate()
{
base.OnApplyTemplate();

UpdateVisualStates(false);
ChangeVisualState(false);
}

protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
Expand All @@ -77,10 +83,10 @@ protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
templateSettings.EllipseOffset = new Thickness(0, maxSideLength / 2 - ellipseDiameter, 0, 0);
templateSettings.MaxSideLength = maxSideLength;

UpdateVisualStates(true);
ChangeVisualState(true);
}

private void UpdateVisualStates(bool useTransitions)
private void ChangeVisualState(bool useTransitions)
{
VisualStateManager.GoToState(this, IsActive ? ActiveState : InactiveState, useTransitions);
VisualStateManager.GoToState(this, TemplateSettings.MaxSideLength < 60 ? SmallState : LargeState, useTransitions);
Expand Down
2 changes: 1 addition & 1 deletion ModernWpf.Controls/ProgressRing/ProgressRing.xaml
Expand Up @@ -13,7 +13,7 @@
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="MinHeight" Value="20" />
<Setter Property="MinWidth" Value="20" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Focusable" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:ProgressRing">
Expand Down
39 changes: 39 additions & 0 deletions ModernWpf.Controls/ProgressRing/ProgressRingAutomationPeer.cs
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Windows.Automation.Peers;
using ModernWpf.Controls;

namespace ModernWpf.Automation.Peers
{
public class ProgressRingAutomationPeer : FrameworkElementAutomationPeer
{
public ProgressRingAutomationPeer(ProgressRing owner) : base(owner)
{
}

protected override string GetClassNameCore()
{
return nameof(ProgressRing);
}

protected override string GetNameCore()
{
string name = base.GetNameCore();

if (Owner is ProgressRing progressRing)
{
if (progressRing.IsActive)
{
return Strings.ProgressRingIndeterminateStatus + name;
}
}
return name;
}

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.ProgressBar;
}
}
}
Expand Up @@ -29,7 +29,7 @@ public override object GetPattern(PatternInterface patternInterface)

protected override string GetClassNameCore()
{
return typeof(SplitButton).FullName;
return nameof(SplitButton);
}

protected override AutomationControlType GetAutomationControlTypeCore()
Expand Down
Expand Up @@ -29,7 +29,7 @@ public override object GetPattern(PatternInterface patternInterface)

protected override string GetClassNameCore()
{
return typeof(ToggleSplitButton).FullName;
return nameof(ToggleSplitButton);
}

protected override AutomationControlType GetAutomationControlTypeCore()
Expand Down
2 changes: 1 addition & 1 deletion ModernWpf/ProgressBar/ProgressBarAutomationPeer.cs
Expand Up @@ -40,7 +40,7 @@ public override object GetPattern(PatternInterface patternInterface)

protected override string GetClassNameCore()
{
return typeof(ProgressBar).FullName;
return nameof(ProgressBar);
}

protected override string GetNameCore()
Expand Down
9 changes: 9 additions & 0 deletions ModernWpf/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions ModernWpf/Resources/Strings.resx
Expand Up @@ -269,4 +269,8 @@
<value>Paused</value>
<comment>This is used to announce Paused state.</comment>
</data>
<data name="ProgressRingIndeterminateStatus" xml:space="preserve">
<value>Busy</value>
<comment>This is used to announce Indeterminate state.</comment>
</data>
</root>

0 comments on commit 261560f

Please sign in to comment.