1- using System . Linq ;
1+ using System ;
2+ using System . Linq ;
23using System . Threading . Tasks ;
34using Xamarin . CommunityToolkit . UI . Views ;
45using Xamarin . Forms ;
6+ using Xamarin . Forms . Internals ;
57using Xamarin . Forms . Platform . UWP ;
68
79namespace Xamarin . CommunityToolkit . Extensions
@@ -11,7 +13,7 @@ public static partial class NavigationExtensions
1113 static void PlatformShowPopup ( BasePopup popup )
1214 {
1315 popup . Parent = GetCurrentPage ( Application . Current . MainPage ) ;
14- Platform . CreateRenderer ( popup ) ;
16+ CreateRenderer ( popup ) ;
1517
1618 // https://github.com/xamarin/Xamarin.Forms/blob/0c95d0976cc089fe72476fb037851a64987de83c/Xamarin.Forms.Platform.iOS/PageExtensions.cs#L44
1719 Page GetCurrentPage ( Page currentPage )
@@ -38,5 +40,22 @@ Page GetCurrentPage(Page currentPage)
3840 PlatformShowPopup ( popup ) ;
3941 return popup . Result ;
4042 }
43+
44+ /// <summary>
45+ /// ATTENTION: Create the Renderer for UWP Don't use the one Provided by Xamarin.Forms, Causes a crash in Native Compiled Code
46+ /// 1. DefaultRenderer is PopupRenderer instead of DefaultRenderer()
47+ /// 2. No Invalid Cast Exceptions in UWP Native when the Xamarin Forms Renderer Functions is used.
48+ /// </summary>
49+ /// <param name="element">Element for getting the renderer</param>
50+ // https://github.com/xamarin/Xamarin.Forms/blob/5.0.0/Xamarin.Forms.Platform.UAP/Platform.cs
51+ static void CreateRenderer ( VisualElement element )
52+ {
53+ if ( element == null )
54+ throw new ArgumentNullException ( nameof ( element ) ) ;
55+
56+ var renderer = Registrar . Registered . GetHandlerForObject < IVisualElementRenderer > ( element ) ?? new PopupRenderer ( ) ;
57+
58+ renderer . SetElement ( element ) ;
59+ }
4160 }
42- }
61+ }
0 commit comments