I am working on Silverlight application and I want to make Image mousedouble click event,but there is no inbuilt mousedouble click in image control so I can do this..
Thanks...!!
The key to accomplishing this is to check for two things:
Measure the TimeSpan between two mouse clicks. Verify it is less than around 300 milliseconds.
Make certain the mouse has not moved more than a few pixels.
Try this http://www.michaelsnow.com/2010/05/10/silverlight-tip-of-the-day-17-double-click/
Regards.
The simplest way is to use a timer.
In the click event handler you have the following cases:
No timer. This is the first click, so start the timer and store the cursor location if necessary.
Timer running. This is potentially the second click. If the cursor hasn't moved then perform the single click action. Stop the timer.
The timer should stop itself after the double click interval (500 ms say) has expired.
Related
I am having trouble using the tap event, I made the space shooter with a different theme and I want to turn it into mobile, but when I hold down the object I created for the tap event, the image angle changes only once, I want it to continue continuously when I hold it down, can you help?
Here is the code I wrote inside the tap event:
with (obj_tuna)
{
image_angle -= 5;
}
A tap is a quick touch where you press and release quickly (just like a mouseclick), so it only recognises your action as a quick press, rather than holding down.
I'm not familiar with mobile platforms, but I notice with a quick search that mouse functions also work with touch functions. So perhaps, if you replace your tap event with a mouse event (or replace a Tap Event with a mouse function in the Step Event), then it may work.
Source: https://forum.yoyogames.com/index.php?threads/how-to-detect-when-a-player-holds-down-on-the-screen.63997/post-383553
From a production application, we notice that our WPF buttons fire the ICommand.Execute method twice on fast double click.
Now, on every Command, the application is covered with a full-screen spinner animation, preventing any further interaction with the application.
This github repo contains a minimalistic repro of the issue. Note that:
when the Button's Command fires, the "IsBusy" flag is set to true
as a consequence, the BusyIndicator overlay will be shown
as a consequence, the Button cannot be pressed again until after 300ms
However, especially on slow computers, when fast double-clicking (really fast, like gaming fast that is), it is possible to fire the command twice without the BusyIndicator blocking the second call (this can be seen if the output shows 2 'click' lines right after one another).
This is unexpected behavior to me, as the IsBusy flag is set to true right away on the UI thread.
How come a second click is able to pass through?
I would expect the IsBusy Binding to show the overlay on the UI thread, blocking any further interaction?
The github sample also contains 2 workarounds:
using the ICommand.CanExecute to block the Execute handler
using the PreviewMouseDown to prevent double clicks
I'm trying to understand what the issue is.
What work-around would you prefer?
Diagnosis
This is only my guess and not a solid and confirmed info, but it seems that when you click the mouse button, the hit-testing is done immediately, but all the mouse related events are only scheduled to be raised (using the Dispatcher I presume). The important thing is that the control that is clicked is determined at the time the click occurred, and not after the previous click has been completely handled (including all UI changes that potentially follow).
So in your case, even if the first click results in showing the BusyIndicator covering (and thus blocking) the Button, if you manage to click for the second time before the BusyIndicator is actually shown (and that does not happen immediately), the click event on the Button will be scheduled to be raised (which will happen after the BusyIndicator is shown), causing the command to be executed again even though at that point the BusyIndicator will possibly be blocking the Button.
Solution
If your goal is to prevent command execution while the previous one is still executing the obvious choice is to make the Command.CanExecute result depend on the state of the IsBusy flag. Moreover, I wouldn't even call it a workaround, but a proper design.
What you're facing here is a clear-cut example of why you shouldn't make your business logic rely on UI. Firstly, because rendering strongly depends on the machine's processing power, and secondly because covering a button with another control by far does not guarantee the button cannot be "clicked" (using for example UI Automation framework).
.NET CF WinForms app runs on Windows CE5 and CE7 devices, with touchscreen.
We hook up to MouseUp event rather than Click in our Button implementation (because of apparent problems with touchscreen sensitivity).
We also hook up a Windows Message filter on application message queue, and filter out MouseDown and/or MouseUp messages based on certain conditions (e.g. screen backlight is off). Normally messages are let through.
Another thing to note - all screens in the application are implemented as controls, and kept in memory forever, just sent to the background. We use OpenNETCF Button2 and Application2.
Now there's a very strange problem, where particular button event handlers get "stuck": event is fired when button is pressed, as expected, but then again after a random time interval - sometimes 20-30 minutes after!
There would be screen interaction in the meanwhile, user presses other buttons, the original screen control and the button become invisible, and then suddenly - typically on next screen touch - the same MouseUp handler for this button is fired again, and then keeps firing.
It also seems to happen with different buttons in the same, certain position on the screen, not each and every button.
The primary question here is - how on earth can an event (MouseUp message for this particular control?) get stored somewhere, and then activated/sent again some time after?
Control is invisible by the time, so it can't be physical touch, presumably.
In Windows Phone 7 Silverlight is there a way to be able to have a button that while I have it selected it calls on a callback function. Either that, or have to functions one for when the button is selected and one for when the button is released. Any ideas as how to do this?
Note that I have already looked at the the toolkit, and the gestures they provide do not include this.
Thanks!
you could look at this in-depth article on gestures:
http://windowsphonegeek.com/articles/WP7-GestureService-in-depth--key-concepts-and-API
specifically the Tap and hold gesture might work for you.
These events would be applicable:
•GestureBegin
The GestureBegin event.
public event EventHandler<GestureEventArgs> GestureBegin;
•GestureCompleted
The GestureCompleted event.
public event EventHandler<GestureEventArgs> GestureCompleted;
On MouseLeftButtonDown start a timer that will Tick until Button is released. Also, you have a control on timer tick Interval
Are you trying to create an action that is similar to the list item tilt effect. or like the video scrub bar. both of those operate when finger is down on the screen, then return to previous state when you remove your finger?
For future reference, and to save some future soul the frustration of why the heck MS didn't implement this in the first place as part of their SDK...
I ended up solving this problem by using ManipulationStarted to record the start time, and ManipulationEnd to record the end time of the gesture, and a separate thread to keep track of the ticks in between.
I am extremely Sorry for this long post. I need some help on c# wpf issues. I have build a complicated UI(somehow) and there is some buttons... like start and stop and others.
When i click the start button a execution process starts with communicating with some protocol layer and others and it is a long process .. and during this process i have to show some notification UI like "Enter a Text", "Select Something" etc... this time i have to show some wpf window object... and after some time i have to automatically destroy the window and go with processing again.
At first i tried to run the execution in the Main window class. But it results that when the execution starts.. user can't click anything and ui doesno't respond rather just hangs. I investigate the problem... and found that UI is busy with processing in the execution on protocol layer so its not responding.
Here is my problem... can u give me some solution that...
i will have 2 button..start and stop
when i click the start button... a large process will start( like nested for loop with a large int which will continue for 50 seconds) in function named Processor.
at time of processing the function Processor will create several window and show them wait for 5-10 seconds and also destroy them. or user click;s on the window
And the whole time the stop button should be clickable so that when i click the stop button .. the process should be stop.
I tried this with backgroundworker, dispatcher... and using separate thread. but no luck. I guess i am missing something. because if i wait for some result showing a window..the window will definitely hang.. and if i separate them with different thread.. it will not communicate with each other. please give me some suggestions
Dispatcher is definitely the solution. You may need to set the Dispatcher Priority. Sharing some relevant code may also reveal some issues.
BackgroundWorker should do what you need. Set WorkerSupportsCancellation and WorkerReportsProgress to true.
I wouldn't suggest popping up multiple windows. Pop up one window to display status. In your loop in DoWork, call BackgroundWorker.ReportProgress. Then in the ProgressChanged event handler, update the status of the window.
To implement Stop:
In your DoWork method you need to check the CancellationPending property on the BackgroundWorker in your loop. When it is true you need to exit that method. On the stop button click, call BackgroundWorker.CancelAsync().