Skip to content

Commit 4c40b33

Browse files
committed
Added IValueProvider capability to TokenizingTextBoxAutomationPeer
1 parent 5844ec0 commit 4c40b33

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBoxAutomationPeer.cs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
using Microsoft.Toolkit.Uwp.UI.Controls;
77
using Windows.UI.Xaml.Automation;
88
using Windows.UI.Xaml.Automation.Peers;
9+
using Windows.UI.Xaml.Automation.Provider;
910
using Windows.UI.Xaml.Controls;
1011

1112
namespace Microsoft.Toolkit.Uwp.UI.Automation.Peers
1213
{
1314
/// <summary>
1415
/// Defines a framework element automation peer for the <see cref="TokenizingTextBox"/> control.
1516
/// </summary>
16-
public class TokenizingTextBoxAutomationPeer : ListViewBaseAutomationPeer
17+
public class TokenizingTextBoxAutomationPeer : ListViewBaseAutomationPeer, IValueProvider
1718
{
1819
/// <summary>
1920
/// Initializes a new instance of the <see cref="TokenizingTextBoxAutomationPeer"/> class.
@@ -26,6 +27,14 @@ public TokenizingTextBoxAutomationPeer(TokenizingTextBox owner)
2627
{
2728
}
2829

30+
/// <summary>Gets a value that indicates whether the value of a control is read-only.</summary>
31+
/// <returns>**true** if the value is read-only; **false** if it can be modified.</returns>
32+
public bool IsReadOnly => !this.OwningTokenizingTextBox.IsEnabled;
33+
34+
/// <summary>Gets the value of the control.</summary>
35+
/// <returns>The value of the control.</returns>
36+
public string Value => this.OwningTokenizingTextBox.Text;
37+
2938
private TokenizingTextBox OwningTokenizingTextBox
3039
{
3140
get
@@ -34,6 +43,13 @@ private TokenizingTextBox OwningTokenizingTextBox
3443
}
3544
}
3645

46+
/// <summary>Sets the value of a control.</summary>
47+
/// <param name="value">The value to set. The provider is responsible for converting the value to the appropriate data type.</param>
48+
public void SetValue(string value)
49+
{
50+
this.OwningTokenizingTextBox.Text = value;
51+
}
52+
3753
/// <summary>
3854
/// Called by GetClassName that gets a human readable name that, in addition to AutomationControlType,
3955
/// differentiates the control represented by this AutomationPeer.
@@ -50,8 +66,8 @@ protected override string GetClassNameCore()
5066
/// <returns>
5167
/// Returns the first of these that is not null or empty:
5268
/// - Value returned by the base implementation
53-
/// - Name of the owning Carousel
54-
/// - Carousel class name
69+
/// - Name of the owning TokenizingTextBox
70+
/// - TokenizingTextBox class name
5571
/// </returns>
5672
protected override string GetNameCore()
5773
{
@@ -62,12 +78,22 @@ protected override string GetNameCore()
6278
}
6379

6480
name = AutomationProperties.GetName(this.OwningTokenizingTextBox);
65-
if (!string.IsNullOrEmpty(name))
66-
{
67-
return name;
68-
}
81+
return !string.IsNullOrEmpty(name) ? name : base.GetNameCore();
82+
}
6983

70-
return base.GetNameCore();
84+
/// <summary>
85+
/// Gets the control pattern that is associated with the specified Windows.UI.Xaml.Automation.Peers.PatternInterface.
86+
/// </summary>
87+
/// <param name="patternInterface">A value from the Windows.UI.Xaml.Automation.Peers.PatternInterface enumeration.</param>
88+
/// <returns>The object that supports the specified pattern, or null if unsupported.</returns>
89+
protected override object GetPatternCore(PatternInterface patternInterface)
90+
{
91+
return patternInterface switch
92+
{
93+
PatternInterface.Value => this,
94+
PatternInterface.Selection => this,
95+
_ => base.GetPatternCore(patternInterface)
96+
};
7197
}
7298

7399
/// <summary>
@@ -97,4 +123,4 @@ protected override IList<AutomationPeer> GetChildrenCore()
97123
return peers;
98124
}
99125
}
100-
}
126+
}

0 commit comments

Comments
 (0)