我想使用 Xamarin 社区工具包弹出窗口显示一个弹出窗口,但我尝试使用 Shell 导航到它我收到错误“System.NullReferenceException Message=Object reference not set to an instance of an object”。
我的弹出窗口的 xaml:
<?xml version="1.0" encoding="utf-8" ?>
<xct:Popup
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
x:Class="Restuco_Tables.Views.AddAreaPopup"
Shell.PresentationMode="ModalAnimated"
Size="300, 300">
<StackLayout>
<Label Text="This is a Popup!" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"/>
</StackLayout>
</xct:Popup>
代码隐藏:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class AddAreaPopup : Popup
{
public AddAreaPopup()
{
InitializeComponent();
}
}
我已经在 AppShell 中注册了路由:
Routing.RegisterRoute(nameof(AddAreaPopup), typeof(AddAreaPopup));
我使用 Shell 对弹出窗口的调用:
private async void tbiNewArea_Clicked(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("/AddAreaPopup");
}