1
- using System . Linq ;
1
+ using System ;
2
+ using System . Linq ;
2
3
using System . Threading . Tasks ;
3
4
using Xamarin . CommunityToolkit . UI . Views ;
4
5
using Xamarin . Forms ;
6
+ using Xamarin . Forms . Internals ;
5
7
using Xamarin . Forms . Platform . UWP ;
6
8
7
9
namespace Xamarin . CommunityToolkit . Extensions
@@ -11,7 +13,7 @@ public static partial class NavigationExtensions
11
13
static void PlatformShowPopup ( BasePopup popup )
12
14
{
13
15
popup . Parent = GetCurrentPage ( Application . Current . MainPage ) ;
14
- Platform . CreateRenderer ( popup ) ;
16
+ CreateRenderer ( popup ) ;
15
17
16
18
// https://github.com/xamarin/Xamarin.Forms/blob/0c95d0976cc089fe72476fb037851a64987de83c/Xamarin.Forms.Platform.iOS/PageExtensions.cs#L44
17
19
Page GetCurrentPage ( Page currentPage )
@@ -38,5 +40,22 @@ Page GetCurrentPage(Page currentPage)
38
40
PlatformShowPopup ( popup ) ;
39
41
return popup . Result ;
40
42
}
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
+ }
41
60
}
42
- }
61
+ }
0 commit comments