gor*_*izu 7 c# windows oop uwp
目前正在开发通用Windows平台应用程序,无法访问导航到页面上的参数
传递参数的代码:
var ente = this.DataGrid.SelectedItem as Ente;
var Id = ente.Id;
Frame.Navigate(typeof(EntiEdit), Id);
Run Code Online (Sandbox Code Playgroud)
这是"NavigatedTo"页面
protected override void OnNavigatedTo(NavigationEventArgs e) {
string Id = e.Parameter as string;
}
Run Code Online (Sandbox Code Playgroud)
我如何在其他方法中使用此字符串?事件覆盖受到保护,因此无法访问其内容.
提前致谢
Vad*_*nov 13
您应该将参数保存到类字段或属性以访问它:
public class EntiEdit : Page
{
private string _entityId;
protected override void OnNavigatedTo(NavigationEventArgs e)
{
_entityId = e.Parameter as string;
}
}
Run Code Online (Sandbox Code Playgroud)
如果您需要在导航页面后启动一些处理,您可以从事件处理程序执行此操作:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var entityId = e.Parameter as string;
EntityData = LoadEntity(entityId);
DoSomeOtherRoutine(entityId);
}
Run Code Online (Sandbox Code Playgroud)