want to have single and double click on image in WP7 application - c#

I want to implement different functionalities for single and double click on image.
I was earlier using Manipulationstarted event .What could be used now?
I am using help from click count
but (e.ClickCount) is not supported

You can do this with the gestures in the Silverlight for Windows Phone Toolkit
e.g.:
<Image Source="filename.png" >
<Controls:GestureService.GestureListener>
<Controls:GestureListener
Tap="GestureListener_Tap"
DoubleTap="GestureListener_DoubleTap" />
</Controls:GestureService.GestureListener>
</Image>
Beware that the tap event will always be called even when the double-tap event is also called. You could attempt to work round this by having a check in the tap event. (You'd need to have a short timer running on a different thread and if the double click isn't tirggered in this time then assume a double click.)
HOWEVER
From a usability point of view, you may make it easier on your users by having a tap event and a context (tap and hold) menu. This will make it much harder for the user to accidentally select the wrong option and it also gets rid of the problem above.
Having an object support both a tap (or click) and double tap event is not common because it's harder to discover or indicate to users and is easy to use the wrong action. Adding a context menu (right click menu on a PC) is the common convention for adding multiple options to users.
There is a ContextMenu also included in the Toolkit.

Shaireen,
Check out my simple blog article here: The simplest way to detect DoubleClick in Silverlight. That should give you the ability to detect both single Click's and DoubleClick's.
Good luck,
Jim McCurdy

You can use Tapped event for single click and DoubleTapped event for double click in windows phone 8.1

Why you don't have your own local counter variable.

Related

What event can be used to detect when WinUI3 TeachingTip has opened or loaded

I am using a TeachingTip control in a C# WinUI3 desktop app. It mostly works OK, but I don't seem to see any event that is triggered when the control has opened (loaded) or is opening.
The control properties let me add an OnLoaded event, but that is not being triggered.
Would appreciate any pointers on adding such a handler. I note that the only listed supported events for this control are: ActionButtonClick, CloseButtonClick, Closed and Closing.
Thanks very much.
You could handle the Loaded event for the TeachingTip's root element:
<TeachingTip ...
Title="..."
Subtitle="...">
<TextBlock Loaded="OnLoaded" />
</TeachingTip>
Thank you for your response. I had supposed it would be something like this, and I may end up doing that. However, at the moment I'm using the PointerPressed handler for the element that opens the TeachingTip. It's good to know there are multiple ways to skin this cat.
Best regards.

How to detect window title change in C# using events (not polling)

I want to be able to detect using events, when a Window (not necessarily the application I'm creating) changes its title.
My ideas (but none of them uses a specialized event):
Add an event to the mouse click and keyboard strokes, that way I can detect when the title will change, but it's not perfect, since the title may change a few seconds after the last click (e.g. loading a website)
Do some polling only on whitelisted applications
EDIT: I managed to put the EVENT_SYSTEM_CAPTURESTART hook, which captures clicks. It does work for changing tabs, but for loading new pages, it will not capture the change because pages usually take some time to load.
I'm doing this by using UIA (as suggested by Hans). I detect when a new window opens, get the UIA element, and subscribe to the property changed event handler for it for the NameProperty.
Automation.AddAutomationPropertyChangedEventHandler(
<your window AutomationElement>,
TreeScope.Element,
<your delegate>,
AutomationElement.NameProperty);

How to manipulate a control without any pattern implemented?

I'm trying to implement the automation test via UIAutomation for our project. But lots of the controls are not standrad, and proper patterns are also not implemented for that controls. How should I to manipulate the controls via UIAutomation framework in this case?
For example, a button in our product is implemented via a Pane, and the invoked pattern is not implemented as well. How should I click the button? (To avoid installing VS on the test machine, I don't want to use Mouse.Click() in Microsoft.VisiualStudio.TestTools.UITesting namespace) Is there a way to do that only using UIAutomation framework or something else embedded in .net framework? Thanks in advance! (If the proper pattern is implemented, Below code will work. And as a new user, I cannot post the screenshot for your reference, sorry!)
object temp = null;
if (btnTest.TryGetCurrentPattern(InvokePattern.Pattern, out temp))
{
InvokePattern btnTestPattern = temp as InvokePattern;
btnTestPattern.Invoke();
}
The only way to interact when Control Patterns are not implemented is to go clicking around stuff.
I would suggest try following to avoid maximum errors.
Before sending the click, make sure the parent of button(pane or window is set to foreground)
Instead of sending the click to corner of the AutomationElement, try sending it in midpoint, of the element,
Also, try hovering over the element first, the wait like 200ms, and then send click, So that you are sure to see execution.[Trust me, this helps debugging a lot and avoids many issues.]
The best thing would be, if those guys who implement the system would implement server-side UIA provider to their UI Elements!
But often that's not possible..., I used the following workaround (at least for clicking/toggling):
AutomationElement yourAE = ...// some code to find the right AutomationElement (AE)
clickablePoint = yourAE.GetClickablePoint();
also BoundingRectangleProperty could be of help
If you receive that clickable point you can use
System.Windows.Forms.Cursor.Position = new System.Drawing.Point((int)clickablePoint.X, (int)clickablePoint.Y);
to move to the location, and than click it via InputSimulator or some win32 (user32.dll) commands.
(note: of course you can also use InputSimulator or win32 to move the mouse - but I had some problems with the InputSimulator when it came to several screens with different locations or resolutions - so Cursor.Position was the easiest approach, which is also very reliable)

Monodevelop: Porting from C#/Visual Studio: Double Click disappear

For the last 2 month I've written application in C# in Visual Studio. Now i have to port that application to Linux by Monodevelop. Well, I already solved most of the porting errors, but there is one that i cant figure out. All double click and mouse double click events from Visual Studio stopped working - I even created small 1-form application that i ported to Mono with only form and one event (double click) - it also didnt work - so that means Monodevelop cant port double click events from Visual Studio ? I already checked WND_Proc function and Linux dont throw up any corresponding double-click event (it was 515 for in window and 3 hundred something on title bar...). Im already giving up and preparing for writing additional code to fix all double-click issue in my code but maybe someone has an answer.
Im using Ubuntu linux (if its neccesary i might tommorow check kernel version), MONO: 2.8.3, Visual Studio 2008 and project in .NET 3.5.
When implementing mouse clicks, there are two main differences between Windows and Gtk# that you should keep in mind:
Gtk# does not offer a 'double-click' signals ('Events' in Windows lingo), but only single 'click' signals. However Gdk library does implements both double-click and triple-click with its EventButton class!
Gtk# differentiates between Widgets (or 'Controls' in Windows lingo) and 'Containers' (there is no direct comparable in Windows). Most widgets placed on a Gtk# form will NOT receive mouse click events. In order to receive a mouse event you need to place the widget inside a specific container - like EventBox.
Here is how you do it Gtk#:
A. Add an EventBox containter to your form (in the example below: eventbox1). You can place it behind other Widgets or since it is not visible, unless you specifically select it to be (or change its background color). You can put a widget inside the EventBox, but you are limited to only one widget, that will also get the shape and size of the EventBox.
B. Add to this EventBox the signal 'ButtonPressEvent' out of the "Common Widget Signals" (in the example below: OnEventbox1ButtonPressEvent)
Every time a mouse button (left, middle or center or a combination) is clicked inside the EventBox, it will trigger this event and the function OnEventbox1ButtonPressEvent() will be called. If you need to identify the button that was clicked while handling this event, use the uint value in: args.Event.Button typically '1' will be the left mouse button, '2' the center button and '3' the right button ('2' might be also when both left and right buttons are clicked).
By the way, mouse motion events (without a button press) are not sent by default. So if you need to sense them you will need to add the PointMotionMask as well in the first like of the code example below.
Here is a code example of the ButtonPress Event Handler (the EventBox name is 'eventbox1') catching a double-click event using the EventButton class:
// The following line is may not be needed but is here to show how to do it
eventbox1.GdkWindow.Events = eventbox1.GdkWindow.Events | Gdk.EventMask.ButtonPressMask;
protected void OnEventbox1ButtonPressEvent (object o, ButtonPressEventArgs args)
{
if( ((Gdk.EventButton)args.Event).Type == Gdk.EventType.TwoButtonPress)
System.Media.SystemSounds.Beep.Play (); // Play a sound only if this is a double-click event
}
The order of the events received (in case of a double click) is:
Gdk.EventType.ButtonPress
Gdk.EventType.ButtonRelease
Gdk.EventType.ButtonPress
Gdk.EventType.TwoButtonPress
Gdk.EventType.ButtonRelease
Hope that helps!
GTK# treats double-click events differently than Windows Forms. You're going to have to write code to translate the events. If you're doing that, you may as well spend the time arguing against double-click as an idiom.

c# simulate click in context menu

So my question is:
I got an Windows Forms application in C# and an webBrowser control in this application. When you for example right-click on a video in youtube, a context menu shows up. Now, is it possible to programmatically rightclick in the webBrowser control an then, again programmatically, click a specific entry in that context menu?
Yes it is, but you always have to start from the same pixel, or better said an actual pixel range, so you can be sure that the clicked result will be the required one. Also you cant click an item by specifying its text, you must do everything programatticaly, from the graphics point of view(just work on the X - Y Axis since its only 2 dimensional). That is the way most web bots are made for various purposes.
Do you really have to simulate a click of the context menu or is just having the desired action good enough? If so than you can just get the item from the ContextMenu.Items list and assuming it a button raise its Click event. If you do need to at least show the context menu while do this you can call the ContextMenu.Show event. This all assumes that the contextmenu for your WebBrowser control is public (not some third party inherited control that hides it or something).

Categories