vb.net - Back button closing app instead of going back on Windows Phone 8.1 -
i've created simple windows phone 8.1 app in visual studio 2013 , added 2 basic pages, along code navigate second screen when button on first screen clicked. going second screen works fine, when hardware button pressed, app closes. want app go first page when button pressed.
i have followed instructions in navigationhelper.vb
, added sub new()
initialization commands, button still not work. how can pressing work correctly? in advance.
here code:
basicpage1.xaml.vb
:
imports app1.common public notinheritable class basicpage1 inherits page private withevents _navigationhelper new navigationhelper(me) private readonly _defaultviewmodel new observabledictionary() public readonly property navigationhelper navigationhelper return _navigationhelper end end property sub new() initializecomponent() me._navigationhelper = new common.navigationhelper(me) addhandler me._navigationhelper.loadstate, addressof navigationhelper_loadstate addhandler me._navigationhelper.savestate, addressof navigationhelper_savestate end sub public readonly property defaultviewmodel observabledictionary return _defaultviewmodel end end property private sub navigationhelper_loadstate(sender object, e loadstateeventargs) handles _navigationhelper.loadstate end sub private sub navigationhelper_savestate(sender object, e savestateeventargs) handles _navigationhelper.savestate end sub #region "navigationhelper registration" protected overrides sub onnavigatedto(e navigationeventargs) _navigationhelper.onnavigatedto(e) end sub protected overrides sub onnavigatedfrom(e navigationeventargs) _navigationhelper.onnavigatedfrom(e) end sub #end region private sub button_click(sender object, e routedeventargs) handles button.click frame.navigate(gettype(basicpage2)) end sub end class
basicpage2.xaml.vb
:
imports app1.common public notinheritable class basicpage2 inherits page private withevents _navigationhelper new navigationhelper(me) private readonly _defaultviewmodel new observabledictionary() public readonly property navigationhelper navigationhelper return _navigationhelper end end property sub new() initializecomponent() me._navigationhelper = new common.navigationhelper(me) addhandler me._navigationhelper.loadstate, addressof navigationhelper_loadstate addhandler me._navigationhelper.savestate, addressof navigationhelper_savestate end sub public readonly property defaultviewmodel observabledictionary return _defaultviewmodel end end property private sub navigationhelper_loadstate(sender object, e loadstateeventargs) handles _navigationhelper.loadstate end sub private sub navigationhelper_savestate(sender object, e savestateeventargs) handles _navigationhelper.savestate end sub #region "navigationhelper registration" protected overrides sub onnavigatedto(e navigationeventargs) _navigationhelper.onnavigatedto(e) end sub protected overrides sub onnavigatedfrom(e navigationeventargs) _navigationhelper.onnavigatedfrom(e) end sub #end region end class
the full solution here: https://github.com/orangeflash81/simplewpapp
i fixed problem myself adding event handler using addhandler
, using frame.navigate
go first page. added code:
sub new() addhandler hardwarebuttons.backpressed, addressof backpressed end sub sub backpressed(sender object, e backpressedeventargs) e.handled = true frame.navigate(gettype(basicpage1)) end sub
Comments
Post a Comment