【发布时间】:2023-01-11 11:45:45
【问题描述】:
我有一个 Maui 应用程序,带有项目集合视图和项目详细信息视图。 在集合视图中点击某个项目时,我想导航到详细信息视图。 我使用 Maui Shell 导航。 该代码来自 Xamarin 应用程序,它曾经在其中工作。 该路由已在 AppShell.xaml 中注册
在收集页面代码后面的点击事件处理程序中
async void OnItemTapped(ItemViewModel itemVM)
{
string route =
$"//{nameof(ItemPage)}?{nameof(ItemPage.Id)}={itemVM.Id}";
await Shell.Current.GoToAsync(route);
}
在调试中,我可以验证变量 route 的内容是否符合预期。
详细信息页面代码隐藏(已编辑为相关位):
[XamlCompilation(XamlCompilationOptions.Compile)]
[QueryProperty(nameof(Id), nameof(Id))]
public partial class ItemPage : ContentPage, IDisposable
{
/// <summary>Navigation property to pass Id value.</summary>
public string Id { get; set; }
public TablePartyPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
// Id is populated by navigation.
string id = TablePartyId.FromUrlQueryValue(Id); /* Problem: Id is null here */
var viewModel = new ItemViewModel(
...
);
BindingContext = viewModel;
}
}
在执行 GotoAsync() ItemPage 构造函数时,会执行 ItemPage OnAppearing(),但是,不会填充导航属性。
我错过了什么?
环境是:
- Visual Studio 2022,v17.4.3
- 毛伊岛 v7
【问题讨论】:
标签: maui navigation-properties .net-maui.shell