Question

I'm testing a simple Windows Phone 8 app with the emulator. I discovered that on the initial load of an app, a Button object will not respond correctly to a long press -- if that button is the first thing I click (and let's say I click and hold), it will just trigger the Click event bound to the button as if I had quickly tapped it. However, if I tap somewhere else in the screen and THEN long press the button, it behaves correctly (i.e. it is highlighted but will not perform its Click event until I unclick).

As I don't own a Windows phone, I'm not sure if this is an emulator-specific problem or what. But, assuming it's not, I figure that this is an issue with focus, as I can click somewhere else on the screen, and then long-press the button and have it behave correctly.

My first idea was give the button focus when the app initially loads. However, I can't quite figure out how to do this, as the button doesn't actually get focus when I try using myButton.Focus() in the onNavigatedTo event or the Loaded event (the name "Loaded" seems to be a bit misleading; when I put a breakpoint in the function bound to that event, I can see that the background of my current screen has not been loaded). Is there another function in which I can call myButton.Focus() once the UI has loaded? If there is no way to initially assign the button focus, I'm out of ideas. Does anyone have a work-around for this?

Was it helpful?

Solution

Because the WP8 emulator is a separate Hyper-V machine the first time you click on the emulator it will capture the mouse. This can affect the click/tap (and related events) that are part of your application.

Don't expect a fix for this, just be aware of this and learn to click somewhere neutral in the emulator before you start interacting with it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top