33// See the LICENSE file in the project root for more information.
44
55using Microsoft . Toolkit . Uwp . UI . Controls ;
6+ using Microsoft . Toolkit . Uwp . UI . Extensions ;
7+ using Windows . UI . Xaml . Automation ;
68using Windows . UI . Xaml . Automation . Peers ;
79using Windows . UI . Xaml . Automation . Provider ;
10+ using Windows . UI . Xaml . Controls ;
811
912namespace Microsoft . Toolkit . Uwp . UI . Automation . Peers
1013{
@@ -61,12 +64,7 @@ public void AddToSelection()
6164 /// <summary>Removes the current element from the collection of selected items.</summary>
6265 public void RemoveFromSelection ( )
6366 {
64- CarouselItem owner = this . OwnerCarouselItem ;
65- Carousel parent = owner . ParentCarousel ;
66- if ( parent != null )
67- {
68- parent . SelectedItem = null ;
69- }
67+ // Cannot remove the selection of a Carousel control.
7068 }
7169
7270 /// <summary>Clears any existing selection and then selects the current element.</summary>
@@ -107,25 +105,53 @@ protected override string GetClassNameCore()
107105 /// </returns>
108106 protected override string GetNameCore ( )
109107 {
110- int ? index = this . OwnerCarouselItem . ParentCarousel ? . IndexFromContainer ( this . OwnerCarouselItem ) ;
108+ string name = AutomationProperties . GetName ( this . OwnerCarouselItem ) ;
109+ if ( ! string . IsNullOrEmpty ( name ) )
110+ {
111+ return name ;
112+ }
111113
112- string name = base . GetNameCore ( ) ;
114+ name = this . OwnerCarouselItem . Name ;
113115 if ( ! string . IsNullOrEmpty ( name ) )
114116 {
115- return $ " { name } " ;
117+ return name ;
116118 }
117119
118- if ( this . OwnerCarouselItem != null && ! string . IsNullOrEmpty ( this . OwnerCarouselItem . Name ) )
120+ var textBlock = this . OwnerCarouselItem . FindDescendant < TextBlock > ( ) ;
121+ if ( textBlock != null )
119122 {
120- return this . OwnerCarouselItem . Name ;
123+ return textBlock . Name ;
121124 }
122125
123- if ( string . IsNullOrEmpty ( name ) )
126+ name = base . GetNameCore ( ) ;
127+ if ( ! string . IsNullOrEmpty ( name ) )
124128 {
125- name = this . GetClassName ( ) ;
129+ return name ;
126130 }
127131
128- return $ "{ name } { index } ";
132+ return string . Empty ;
133+ }
134+
135+ /// <summary>
136+ /// Called by GetAutomationId that gets the **AutomationId** of the element that is associated with the automation peer.
137+ /// </summary>
138+ /// <returns>
139+ /// The string that contains the automation ID.
140+ /// </returns>
141+ protected override string GetAutomationIdCore ( )
142+ {
143+ var automationId = base . GetAutomationIdCore ( ) ;
144+ if ( ! string . IsNullOrEmpty ( automationId ) )
145+ {
146+ return automationId ;
147+ }
148+
149+ if ( this . OwnerCarouselItem != null )
150+ {
151+ return this . GetNameCore ( ) ;
152+ }
153+
154+ return string . Empty ;
129155 }
130156
131157 /// <summary>
@@ -143,5 +169,49 @@ protected override object GetPatternCore(PatternInterface patternInterface)
143169
144170 return base . GetPatternCore ( patternInterface ) ;
145171 }
172+
173+ /// <summary>
174+ /// Returns the size of the set where the element that is associated with the automation peer is located.
175+ /// </summary>
176+ /// <returns>
177+ /// The size of the set.
178+ /// </returns>
179+ protected override int GetSizeOfSetCore ( )
180+ {
181+ int sizeOfSet = base . GetSizeOfSetCore ( ) ;
182+
183+ if ( sizeOfSet != - 1 )
184+ {
185+ return sizeOfSet ;
186+ }
187+
188+ CarouselItem owner = this . OwnerCarouselItem ;
189+ Carousel parent = owner . ParentCarousel ;
190+ sizeOfSet = parent . Items . Count ;
191+
192+ return sizeOfSet ;
193+ }
194+
195+ /// <summary>
196+ /// Returns the ordinal position in the set for the element that is associated with the automation peer.
197+ /// </summary>
198+ /// <returns>
199+ /// The ordinal position in the set.
200+ /// </returns>
201+ protected override int GetPositionInSetCore ( )
202+ {
203+ int positionInSet = base . GetPositionInSetCore ( ) ;
204+
205+ if ( positionInSet != - 1 )
206+ {
207+ return positionInSet ;
208+ }
209+
210+ CarouselItem owner = this . OwnerCarouselItem ;
211+ Carousel parent = owner . ParentCarousel ;
212+ positionInSet = parent . IndexFromContainer ( owner ) ;
213+
214+ return positionInSet ;
215+ }
146216 }
147217}
0 commit comments