c# - UWP on screen back button - how to trigger system back event? -
i have uwp app - design has "back" button in screen content, use trigger system navigation event handled in app.xaml.cs file. current click handler, pasted each file needs is:
frame rootframe = window.current.content frame; if (rootframe.cangoback) rootframe.goback(); how instead trigger event, trigger event handler contains code?
in app.xaml.cs, add onlaunced(...):
protected override void onlaunched(launchactivatedeventargs e) { ... if (rootframe == null) { ... // register handler backrequested events systemnavigationmanager.getforcurrentview().backrequested += this.onbackrequested; } ... } where in onbackrequested(...), can in app.xaml.cs:
private void onbackrequested(object sender, backrequestedeventargs e) { frame rootframe = window.current.content frame; if (rootframe.cangoback) { e.handled = true; rootframe.goback(); } } this adapted support multiple frames if implement custom navigation, , can add global handling of showing/hiding button via like:
public void updatebackbutton(frane frame) { bool cangoback = (frame?.cangoback ?? false); systemnavigationmanager.getforcurrentview().appviewbackbuttonvisibility = cangoback ? appviewbackbuttonvisibility.visible : appviewbackbuttonvisibility.collapsed; } you can programmatically call via function in app.xaml.cs or in custom navigation manager:
public bool trygoback(frame frame) { bool handled = false; if (frame?.cangoback ?? false) { handled = true; frame.goback(); } this.updatebackbutton(frame); return handled; }
Comments
Post a Comment