Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 529b72d

Browse files
inforithmicsAndreiMisiukevichjsuarezruizpictosTheCodeTraveler
authored
Fixing Popup Uwp Release Compilation Crash (#1303)
* Fixing Popup Uwp Release Compilation Crash * Update NavigationExtensions.uwp.cs Simplyfy workaround * revert change * Set Renderer in Create Renderer * Update src/CommunityToolkit/Xamarin.CommunityToolkit/Extensions/Navigation/NavigationExtensions.uwp.cs * fixed build Co-authored-by: Andrei <andrei.misiukevich@gmail.com> Co-authored-by: Javier Suárez <javiersuarezruiz@hotmail.com> Co-authored-by: Pedro Jesus <pedrojesus.cefet@gmail.com> Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com>
1 parent 2c26775 commit 529b72d

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/CommunityToolkit/Xamarin.CommunityToolkit/Extensions/Navigation/NavigationExtensions.uwp.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using System.Linq;
1+
using System;
2+
using System.Linq;
23
using System.Threading.Tasks;
34
using Xamarin.CommunityToolkit.UI.Views;
45
using Xamarin.Forms;
6+
using Xamarin.Forms.Internals;
57
using Xamarin.Forms.Platform.UWP;
68

79
namespace 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

Comments
 (0)