目前正在开发通用 Windows 平台应用程序,无法访问导航到页面上的参数
参数传递代码:
var ente = this.DataGrid.SelectedItem as Ente;
var Id = ente.Id;
Frame.Navigate(typeof(EntiEdit), Id);
这是“NavigatedTo”页面
protected override void OnNavigatedTo(NavigationEventArgs e) {
string Id = e.Parameter as string;
}
我如何在我的其他方法中使用这个字符串?事件覆盖受到保护,因此我无法访问其内容。
提前致谢
最佳答案
您应该将参数保存到类字段或属性中以访问它:
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);
}
关于c# - 访问 UWP 页面之间传递的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34832190/