访问在 UWP 页面之间传递的参数

本文关键字:参数 之间 UWP 访问 | 更新日期: 2023-09-27 18:30:37

目前正在开发通用Windows平台应用程序,无法访问导航到页面上的参数

传递参数的代码:

var ente = this.DataGrid.SelectedItem as Ente;
            var Id = ente.Id;
            Frame.Navigate(typeof(EntiEdit), Id);

这是"导航到"页面

protected override void OnNavigatedTo(NavigationEventArgs e) {
         string Id = e.Parameter as string;
        }

如何在其他方法中使用此字符串?事件覆盖受到保护,因此我无法访问其内容。

提前致谢

访问在 UWP 页面之间传递的参数

应将参数保存到类字段或属性中才能访问它:

public class EntiEdit : Page
{
    private string _entityId;
    protected override void OnNavigatedTo(NavigationEventArgs e) 
    {
        _entityId = e.Parameter as string;
    }
}

如果需要在导航页面后启动一些处理,可以从事件处理程序执行此操作:

protected override void OnNavigatedTo(NavigationEventArgs e) 
{
    var entityId = e.Parameter as string;
    EntityData = LoadEntity(entityId);
    DoSomeOtherRoutine(entityId);
}