Skip to content

Commit 73be0aa

Browse files
authored
Merge branch 'master' into shweaver/inappnotifications
2 parents 5932530 + 5f87b23 commit 73be0aa

File tree

15 files changed

+504
-29
lines changed

15 files changed

+504
-29
lines changed

Microsoft.Toolkit.Uwp.SampleApp/Data/PhotoDataItem.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@ public class PhotoDataItem
1111
public string Category { get; set; }
1212

1313
public string Thumbnail { get; set; }
14+
15+
public override string ToString()
16+
{
17+
return Title;
18+
}
1419
}
1520
}

Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
2322
<ProjectReference Include="..\Microsoft.Toolkit.Uwp.UI\Microsoft.Toolkit.Uwp.UI.csproj" />
2423
</ItemGroup>
2524

Microsoft.Toolkit.Uwp.UI.Controls.Layout/BladeView/BladeItemAutomationPeer.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,6 @@ protected override string GetNameCore()
9393
return string.Empty;
9494
}
9595

96-
/// <summary>
97-
/// Called by GetAutomationId that gets the **AutomationId** of the element that is associated with the automation peer.
98-
/// </summary>
99-
/// <returns>
100-
/// The string that contains the automation ID.
101-
/// </returns>
102-
protected override string GetAutomationIdCore()
103-
{
104-
string automationId = base.GetAutomationIdCore();
105-
if (!string.IsNullOrEmpty(automationId))
106-
{
107-
return automationId;
108-
}
109-
110-
if (this.OwnerBladeItem != null)
111-
{
112-
return this.GetNameCore();
113-
}
114-
115-
return string.Empty;
116-
}
117-
11896
/// <summary>
11997
/// Returns the size of the set where the element that is associated with the automation peer is located.
12098
/// </summary>

Microsoft.Toolkit.Uwp.UI.Controls.Layout/Carousel/Carousel.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Linq;
8+
using Microsoft.Toolkit.Uwp.UI.Automation.Peers;
89
using Windows.Foundation;
910
using Windows.UI.Xaml;
1011
using Windows.UI.Xaml.Automation;
12+
using Windows.UI.Xaml.Automation.Peers;
1113
using Windows.UI.Xaml.Controls;
1214
using Windows.UI.Xaml.Input;
1315
using Windows.UI.Xaml.Media;
@@ -520,6 +522,17 @@ protected override void PrepareContainerForItemOverride(DependencyObject element
520522
{
521523
carouselItem.IsSelected = true;
522524
}
525+
526+
carouselItem.ParentCarousel = this;
527+
}
528+
529+
/// <summary>
530+
/// Creates AutomationPeer (<see cref="UIElement.OnCreateAutomationPeer"/>)
531+
/// </summary>
532+
/// <returns>An automation peer for this <see cref="Carousel"/>.</returns>
533+
protected override AutomationPeer OnCreateAutomationPeer()
534+
{
535+
return new CarouselAutomationPeer(this);
523536
}
524537

525538
private void OnCarouselItemSelected(object sender, EventArgs e)
@@ -528,5 +541,11 @@ private void OnCarouselItemSelected(object sender, EventArgs e)
528541

529542
SelectedItem = ItemFromContainer(item);
530543
}
544+
545+
internal void SetSelectedItem(CarouselItem owner)
546+
{
547+
var item = ItemFromContainer(owner);
548+
SelectedItem = item;
549+
}
531550
}
532551
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Collections.Generic;
6+
using Microsoft.Toolkit.Uwp.UI.Controls;
7+
using Windows.UI.Xaml.Automation;
8+
using Windows.UI.Xaml.Automation.Peers;
9+
using Windows.UI.Xaml.Automation.Provider;
10+
using Windows.UI.Xaml.Controls;
11+
12+
namespace Microsoft.Toolkit.Uwp.UI.Automation.Peers
13+
{
14+
/// <summary>
15+
/// Defines a framework element automation peer for the <see cref="Carousel"/> control.
16+
/// </summary>
17+
public class CarouselAutomationPeer : ItemsControlAutomationPeer, ISelectionProvider
18+
{
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="CarouselAutomationPeer"/> class.
21+
/// </summary>
22+
/// <param name="owner">
23+
/// The <see cref="Carousel" /> that is associated with this <see cref="T:Windows.UI.Xaml.Automation.Peers.CarouselAutomationPeer" />.
24+
/// </param>
25+
public CarouselAutomationPeer(Carousel owner)
26+
: base(owner)
27+
{
28+
}
29+
30+
/// <summary>Gets a value indicating whether the Microsoft UI Automation provider allows more than one child element to be selected concurrently.</summary>
31+
/// <returns>True if multiple selection is allowed; otherwise, false.</returns>
32+
public bool CanSelectMultiple => false;
33+
34+
/// <summary>Gets a value indicating whether the UI Automation provider requires at least one child element to be selected.</summary>
35+
/// <returns>True if selection is required; otherwise, false.</returns>
36+
public bool IsSelectionRequired => true;
37+
38+
private Carousel OwningCarousel
39+
{
40+
get
41+
{
42+
return Owner as Carousel;
43+
}
44+
}
45+
46+
/// <summary>Retrieves a UI Automation provider for each child element that is selected.</summary>
47+
/// <returns>An array of UI Automation providers.</returns>
48+
public IRawElementProviderSimple[] GetSelection()
49+
{
50+
return OwningCarousel.ContainerFromItem(this.OwningCarousel.SelectedItem) is CarouselItem selectedCarouselItem
51+
? new[] { this.ProviderFromPeer(FromElement(selectedCarouselItem)) }
52+
: new IRawElementProviderSimple[] { };
53+
}
54+
55+
/// <summary>
56+
/// Gets the control type for the element that is associated with the UI Automation peer.
57+
/// </summary>
58+
/// <returns>The control type.</returns>
59+
protected override AutomationControlType GetAutomationControlTypeCore()
60+
{
61+
return AutomationControlType.List;
62+
}
63+
64+
/// <summary>
65+
/// Called by GetClassName that gets a human readable name that, in addition to AutomationControlType,
66+
/// differentiates the control represented by this AutomationPeer.
67+
/// </summary>
68+
/// <returns>The string that contains the name.</returns>
69+
protected override string GetClassNameCore()
70+
{
71+
return Owner.GetType().Name;
72+
}
73+
74+
/// <summary>
75+
/// Called by GetName.
76+
/// </summary>
77+
/// <returns>
78+
/// Returns the first of these that is not null or empty:
79+
/// - Value returned by the base implementation
80+
/// - Name of the owning Carousel
81+
/// - Carousel class name
82+
/// </returns>
83+
protected override string GetNameCore()
84+
{
85+
string name = this.OwningCarousel.Name;
86+
if (!string.IsNullOrEmpty(name))
87+
{
88+
return name;
89+
}
90+
91+
name = AutomationProperties.GetName(this.OwningCarousel);
92+
if (!string.IsNullOrEmpty(name))
93+
{
94+
return name;
95+
}
96+
97+
return base.GetNameCore();
98+
}
99+
100+
/// <summary>
101+
/// Gets the control pattern that is associated with the specified Windows.UI.Xaml.Automation.Peers.PatternInterface.
102+
/// </summary>
103+
/// <param name="patternInterface">A value from the Windows.UI.Xaml.Automation.Peers.PatternInterface enumeration.</param>
104+
/// <returns>The object that supports the specified pattern, or null if unsupported.</returns>
105+
protected override object GetPatternCore(PatternInterface patternInterface)
106+
{
107+
switch (patternInterface)
108+
{
109+
case PatternInterface.Selection:
110+
return this;
111+
}
112+
113+
return base.GetPatternCore(patternInterface);
114+
}
115+
116+
/// <summary>
117+
/// Gets the collection of elements that are represented in the UI Automation tree as immediate
118+
/// child elements of the automation peer.
119+
/// </summary>
120+
/// <returns>The children elements.</returns>
121+
protected override IList<AutomationPeer> GetChildrenCore()
122+
{
123+
Carousel owner = OwningCarousel;
124+
125+
ItemCollection items = owner.Items;
126+
if (items.Count <= 0)
127+
{
128+
return null;
129+
}
130+
131+
List<AutomationPeer> peers = new List<AutomationPeer>(items.Count);
132+
for (int i = 0; i < items.Count; i++)
133+
{
134+
if (owner.ContainerFromIndex(i) is CarouselItem element)
135+
{
136+
peers.Add(FromElement(element) ?? CreatePeerForElement(element));
137+
}
138+
}
139+
140+
return peers;
141+
}
142+
}
143+
}

Microsoft.Toolkit.Uwp.UI.Controls.Layout/Carousel/CarouselItem.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using Microsoft.Toolkit.Uwp.UI.Automation.Peers;
67
using Windows.UI.Xaml;
7-
using Windows.UI.Xaml.Controls;
8+
using Windows.UI.Xaml.Automation.Peers;
89
using Windows.UI.Xaml.Controls.Primitives;
910
using Windows.UI.Xaml.Input;
1011

@@ -22,6 +23,8 @@ public partial class CarouselItem : SelectorItem
2223
private const string SelectedState = "Selected";
2324
private const string NormalState = "Normal";
2425

26+
private WeakReference<Carousel> parentCarousel;
27+
2528
/// <summary>
2629
/// Initializes a new instance of the <see cref="CarouselItem"/> class.
2730
/// </summary>
@@ -33,6 +36,16 @@ public CarouselItem()
3336
RegisterPropertyChangedCallback(SelectorItem.IsSelectedProperty, OnIsSelectedChanged);
3437
}
3538

39+
internal Carousel ParentCarousel
40+
{
41+
get
42+
{
43+
this.parentCarousel.TryGetTarget(out var carousel);
44+
return carousel;
45+
}
46+
set => this.parentCarousel = new WeakReference<Carousel>(value);
47+
}
48+
3649
/// <inheritdoc/>
3750
protected override void OnPointerEntered(PointerRoutedEventArgs e)
3851
{
@@ -57,6 +70,15 @@ protected override void OnPointerPressed(PointerRoutedEventArgs e)
5770
VisualStateManager.GoToState(this, IsSelected ? PressedSelectedState : PressedState, true);
5871
}
5972

73+
/// <summary>
74+
/// Creates AutomationPeer (<see cref="UIElement.OnCreateAutomationPeer"/>)
75+
/// </summary>
76+
/// <returns>An automation peer for this <see cref="CarouselItem"/>.</returns>
77+
protected override AutomationPeer OnCreateAutomationPeer()
78+
{
79+
return new CarouselItemAutomationPeer(this);
80+
}
81+
6082
internal event EventHandler Selected;
6183

6284
private void OnIsSelectedChanged(DependencyObject sender, DependencyProperty dp)

0 commit comments

Comments
 (0)