@@ -293,6 +293,12 @@ protected override void SetElementChildVisual(AttachedShadowElementContext conte
293293 else
294294 {
295295 base . SetElementChildVisual ( context ) ;
296+
297+ // Reset context.SpriteVisual.Size and RelativeSizeAdjustment to default values
298+ // as they may be changed in the block above.
299+ context . SpriteVisual . Size = Vector2 . Zero ;
300+ context . SpriteVisual . RelativeSizeAdjustment = Vector2 . One ;
301+
296302 context . RemoveAndDisposeResource ( OpacityMaskVisualSurfaceResourceKey ) ;
297303 context . RemoveAndDisposeResource ( OpacityMaskSurfaceBrushResourceKey ) ;
298304 context . RemoveAndDisposeResource ( OpacityMaskVisualResourceKey ) ;
@@ -305,25 +311,33 @@ protected internal override void OnSizeChanged(AttachedShadowElementContext cont
305311 {
306312 Vector2 sizeAsVec2 = newSize . ToVector2 ( ) ;
307313
308- CompositionRoundedRectangleGeometry geometry = context . GetResource ( RoundedRectangleGeometryResourceKey ) ;
309- if ( geometry != null )
314+ if ( context . TryGetResource ( RoundedRectangleGeometryResourceKey , out CompositionRoundedRectangleGeometry geometry ) )
310315 {
311316 geometry . Size = sizeAsVec2 ;
312317 }
313318
314- CompositionVisualSurface visualSurface = context . GetResource ( VisualSurfaceResourceKey ) ;
315- if ( geometry != null )
319+ if ( context . TryGetResource ( VisualSurfaceResourceKey , out CompositionVisualSurface visualSurface ) )
316320 {
317321 visualSurface . SourceSize = sizeAsVec2 ;
318322 }
319323
320- ShapeVisual shapeVisual = context . GetResource ( ShapeVisualResourceKey ) ;
321- if ( geometry != null )
324+ if ( context . TryGetResource ( ShapeVisualResourceKey , out ShapeVisual shapeVisual ) )
322325 {
323326 shapeVisual . Size = sizeAsVec2 ;
324327 }
325328
329+ if ( context . TryGetResource ( OpacityMaskVisualSurfaceResourceKey , out CompositionVisualSurface opacityMaskVisualSurface ) )
330+ {
331+ opacityMaskVisualSurface . SourceSize = sizeAsVec2 + new Vector2 ( MaxBlurRadius * 2 ) ;
332+ }
333+
334+ if ( InnerContentClipMode is InnerContentClipMode . CompositionMaskBrush )
335+ {
336+ context . SpriteVisual . Size = sizeAsVec2 ;
337+ }
338+
326339 UpdateShadowClip ( context ) ;
340+ UpdateVisualOpacityMask ( context ) ;
327341
328342 base . OnSizeChanged ( context , newSize , previousSize ) ;
329343 }
0 commit comments