@@ -156,19 +156,14 @@ private static bool GetDirty(UIElement element)
156
156
return EnsureElementAccessibilityContext ( element ) . Dirty ;
157
157
}
158
158
159
- private static void MarkElementDirty ( UIElement element , bool skipIfNoPeer = false )
159
+ private static void MarkElementDirty ( UIElement element )
160
160
{
161
161
// Retrieve automation peer
162
162
var peer = FrameworkElementAutomationPeer . FromElement ( element ) ;
163
163
164
164
if ( peer == null )
165
165
{
166
- if ( skipIfNoPeer )
167
- {
168
- return ;
169
- }
170
-
171
- throw new InvalidOperationException ( "Element has no automation peer" ) ;
166
+ return ;
172
167
}
173
168
174
169
#if PERF_LOG
@@ -224,7 +219,7 @@ public static void OnChildAdded(UIElement parent, DependencyObject child)
224
219
SetCurrentlyHidingChildren ( parent , ElementAccessibilityContext . HidingChildren . NotSure ) ;
225
220
226
221
// Mark the parent dirty (or skip if there is no associated peer available)
227
- MarkElementDirty ( parent , true ) ;
222
+ MarkElementDirty ( parent ) ;
228
223
}
229
224
230
225
/// <summary>
@@ -238,16 +233,41 @@ public static void OnChildRemoved(UIElement parent)
238
233
parent . UpdateLayout ( ) ;
239
234
240
235
// Mark the parent dirty (or skip if there is no associated peer available)
241
- MarkElementDirty ( parent , true ) ;
236
+ MarkElementDirty ( parent ) ;
242
237
}
243
238
244
239
/// <summary>
245
240
/// Marks accessibility data in UI tree for update after a relevant (to accessibility) property of that element changed.
246
241
/// For example, it is used by <see cref="RichTextBlock"/> to notify when text or structure is changed inside the text block.
247
242
/// </summary>
248
243
/// <param name="uiElement">The <see cref="UIElement"/>.</param>
249
- public static void OnElementChanged ( UIElement uiElement )
244
+ /// <param name="dependencyProperty">The dependency property that changed. It's important to provide this parameter if possible.</param>
245
+ public static void OnElementChanged ( UIElement uiElement , DependencyProperty dependencyProperty = null )
250
246
{
247
+ if ( ReferenceEquals ( UIElement . VisibilityProperty , dependencyProperty ) )
248
+ {
249
+ // add/remove like
250
+ var fe = uiElement as FrameworkElement ;
251
+ if ( fe == null )
252
+ {
253
+ return ;
254
+ }
255
+ var parent = fe . Parent as UIElement ;
256
+ if ( parent == null )
257
+ {
258
+ return ;
259
+ }
260
+
261
+ if ( uiElement . Visibility == Visibility . Visible )
262
+ {
263
+ OnChildAdded ( parent , fe ) ;
264
+ }
265
+ else
266
+ {
267
+ OnChildRemoved ( parent ) ;
268
+ }
269
+ return ;
270
+ }
251
271
// Mark the element dirty
252
272
MarkElementDirty ( uiElement ) ;
253
273
}
0 commit comments