I need handle hardware back button in every pages but it is not working.
I can only invoke OnBackKeyPress in main page. and other pages run same functionality that I put in main page OnBackKeyPress event.
I googled it more than 2 hours but didn't find any solution.
It depends on exactly what you are doing. There are two ways to capture the Back key: override OnBackKeyPress of the PhoneApplicationPage class, or attach an event listener to RootFrame.BackKeyPress. If you are attaching an event listener then even if you leave the current page the event listener will still be attached and will be called whenever the Back key is pressed. You'll need to be more specific with exactly what you are doing, what you expect to see, and what you are seeing.
Related
I have moved my project to prism 7.2
I have quite a few "OnNavigatingTo" and replaced accordingly with InitializeAsync or Initialize
If I remember correctly "OnNavigatingTo" was firing every time you navigated to a page whether to or back. If I was navigating back to a page it would fire whilst Initialize doesn't.
This whether correct or wrong is causing me issues with some of my pages where I was passing back parameters when navigating back .
Is this the intended behavior?
thanks
OnNavigatingTo was only ever supposed to fire once. It's intent was to initialize. There ended up being cases where it fired more than once. Anything you require done once should be placed in IInitialize.Initialize anything that should be fired each time you navigate or requires some logic like Navigated Back to... should be in INavigat[ed|ion]Aware.OnNavigatedTo.
It was this confusion that led so many Prism users to request that the support be dropped and a new API be introduced that made the intent clearer.
I'm playing around with the wearable SDK and created some additional pages for my sample app.
Is there a convenient way to dismiss / delete a single page by e.g. swiping?
I just found calls for adding, but not for removing (even after an action)
As far as I know, this is not possible, because even a multi-page-notification is (from a technical point-of-view) just one single notification which can only disapper in its entirety.
The only possibility I see here is to set a pending intent to a broadcast receiver, figure somehow out on which page the user was when dismissing the notification, and then create a new notification without this page.
I 've seen many WP7 applications, some place event handlers in code, some place event handlers in XAML
Should we add event handler in XAML?
Does that handler automatically unsubscribe to the event when the page is navigated from ?
You can do either, it really doesn't matter! And no, you do not have to worry about adding / removing event handlers when the user navigates from one page to the next. When a page is no longer needed, it is destroyed.
The only time you might want to handle things differently is if you are using the MVVM pattern, when you might want to use commands rather than event handlers.
The loaded event on my MainPage is getting called twice on application startup.
The constructor of the page is only getting once, and I am pretty sure that I am only assigning the event handler once also. What is going on?
Took me a while to work out what was going on, but it turns out the loaded event shouldn't be used on pages for initialization tasks, as it is not guaranteed to be called only once.
OnNavigatedTo should always be used instead. See the MSDN article below.
Typically, you use the OnNavigatedTo method instead of creating an
event handler for the Loaded event. The OnNavigatedTo method is
preferable because it is only called once for each time the page
becomes active. The Silverlight framework raises the Loaded event each
time the element is added to the visual tree, which potentially can
happen more than once when activating a page.
I am trying to use MVVM light messaging to send a value from one page to another during Navigation (for example, send the id of an item that was selected to an edit page). So the list page's viewmodel sends a message and then sends a navigation message to the view which redirects to the edit page. The edit page's viewmodel gets created only when the navigation to the page happens. So when I register for this event in the edit page viewmodel, I never get the message? What is the best solution for this?
Thanks in advance.
Your best solution would be to use the querystring instead of messaging. If you don't use the querystring, you'll have to deal with situations like the application being deactivated (tomestoned), then the user clicking "back" and your application loads the second page without receiving the message.
However, if you want to continue down this path, you can modify your ViewModelLocator such that your page's ViewModel is created immediately (in ctor for instance) instead of as needed. Since the ViewModelLocator is created as soon as your App.xaml is loaded, you know that any view models will be created immediately. As long as your view model is registering for messages in it's constructor it should receive the message.