Windows phone 8.1 Handling App from Close button in the page - windows-phone-8

In my windows phone app, i have to delete some files when user navigates away from a page.
I have handled this on OnBackKeyPress event. This works perfectly fine.
The issue is newer updates of windows phone 8 and windows phone 8.1 also have close button on the top right corner. I have not found a way to handle this event.
Could anyone please let me know how can i handle this event and delete the files.

Rather than using OnBackKeyPress, you should use OnNavigatedFrom. This event is triggered whenever the user leaves the page, no matter how.
If you need to handle only the specific case when the app is suspended/terminated, you can subscribe to the Deactivated and Closing events on the PhoneApplicationService.
PhoneApplicationService.Current.Deactivated += yourHandler;
Note that is the your event handler is a non-static method declared in your page, then you must make sure to unsubscribe the event when leaving the page, to avoid a memory leak. To know when to unsubscribe, you can stick to your OnBackKeyPress logic.

Related

SystemMediaTransportControls track name click event

I'm using SystemMediaTransportControls to control audio playback throughout my Windows Phone 8.1 Universal App.
The controls seem to have a one specific behaviour - the track name and artist act as a clickable button and clicking on it fires the OnLaunched event for the app.
Is there any way to either change the behaviour of this button or at least detect if the OnLaunched event is fired due to user clicking on this button?
Specifically, I need to direct the user to the currently playing album's page in the app when she clicks on this button.
The current behavior is that it launches/reactivates the app associated with the background audio playback. The same behavior applies to the Windows Store Music app.
Here's what I think you could try:
If your app has multiple album pages for currently playing audio, then you might consider subscribing to foreground messages from the background task. You can use "BackgroundMediaPlayer.SendMessageToForeground" to send messages to the foreground and navigate appropriately. Try making the call in the OnLaunched event before the Windows is activated. You should also be able to get currently playing audio information and use that accordingly.
Take a look at the Background Audio for Windows Phone 8.1 sample for more details on how to use background audio. Then you should try what I mentioned to see if that works for you.
Hope this helps.

Manipulation events are not fired on page with a listview

Now I'm developing windows phone 8.1 app with WinRT
I'm trying to support swipe-right-to-go-back gesture in my app.
I try to capture the manipulation events on my page. My page's root is a grid and have a ListView inside. I used the UIElement.AddHandler method with "handledEventsToo=true" to add the event handlers. But when I touch the screen, only the ManipulationStarting event is fired, other events seems to be eat by listview.
Could anyone tell me about the manipulation event behavior or other methods to implement this feature? Thanks!!
You won't normally capture events on LisView, beacause it has a ScrollViewer which intercepts them.
There is a way to do it - you will have to disable ScrollViewer and then perfrom some actions when the events are fired and perform scrolling manually. This answer will guide you.
In case someone encounters this page, I spent the better part of a week figuring out why manipulation events were only firing half the time on my UWP charts using the winRT xaml toolkit.
You may need to check that the background is not null on whatever element has the event handler attached. Templated controls are not necessarily hit test visible unless they have one. Otherwise, the input can go right through to the element behind it.
https://msdn.microsoft.com/en-us/windows/uwp/xaml-platform/events-and-routed-events-overview

Send mouse events to inactive and hidden windows/WPF forms

I'm developing an app that needs to generate mouse events on a window Win32/WPF which may be minimized or hidden from view on the desktop.
I have tried the user32.dll APIs SendInput, SendMessage, PostMessage etc. These work only if the window is visible on the desktop. Would you know about any methods that work for hidden/inactive windows?
I've also tried .NET's UI Automation library. In this case, a window is brought to the front or I'm not able to get a clickable point for the control.
Any ideas how I can proceed? If I can proceed?
I don't know if you're still interested in an answer (I just stumbled upon this question out of sheer dumb luck), but have you tried making a global windows hook?
I have no honest idea on how to properly go about implementing one; but I know you should be able to add a global windows hook to, well, Windows, to listen for whatever events you want (should include mouse and keyboard events!)
Good luck...

Image Viewer Plugin - Part 2

in a former thread ( Adding a user interface to an image viewer plugin ) I have got some good insight on how to add GUI controls to a firebreath plugin. Taxilian pointed out that when I use a windowed plugin under Windows it should be straighforward. Basically like developing any other Windows App.
Now, to make sure I understand correctly. I'm suppose to create a child window from the window handle supplied by the onWindowAttached event. To create such a child window I need to register such windows class with ::RegisterClassEx(...) to have my own Window Procedure. Is that correct? I mean how else would get access to WM_COMMAND events?
Once that is done I need to ::CreateWindowEx(...) my child window with the hwnd from the plugin.
Is that the right way of thinking?
Thanks ahead,
Christian
Actually creating a child window is optional; WM_COMMAND events for your actual plugin window will be delivered encapsulated in a WindowsEvent that you can catch the same way you get an AttachedEvent. All windows events are sent that way.
Another option is to do what you describe and register a new class with a WINPROC and create a child window. The main reason for doing that would be that you might be able to more easily interact with an abstraction like wxWidgets, etc because it will not know what FireBreath is to get events from it that way. Either method should work fine.

Air Native Window Active Window Change

I have a Adobe Air app (AS3, not Flex) that has 2 windows. When I click away from them onto another desktop program, I get an "Deactivate" Event (as you would expect).
When I click on say Window#1 I get an "Activate" Event (as you would expect).
But when I go from Window#1 to Window#2, I get nothing. And I believe this is because the Air application is still the active program, Just a Different Window.
But I have the need to know when I go from 1 window to another.
The horrible solutions I have come up with so far is to have an onEnterFrame and check if the current window is the active window. But I would much prefer to do it a much better way that such a hack.
I have gone though Stage, NativeApplication and Native Window Events and none of them do what I need. Can anyone point me to another Event I may have overlooked?
Listen for window activation events directly on the NativeWindow object. (All display objects dispatch activation/deactivation events, but these are triggered by the application -- or SWF object in the browser -- getting or losing the OS focus.)