MouseLeftButtonDown event not fire while Touching the WPF window - c#

I have a custom control which inherits from Control and I'm trying to trigger MouseLeftButtonDown using Touch on WPF platform.The event MouseLeftButtonDown does not fire while touch the window but its works fine when use mouse device. I have tried the related PreviewMouseLeftButtonDown event also nothing happens while touch the window.
Please suggest me the solution.
Regards,
Jeyasri M

Already in another post
WPF combining MouseDown and TouchDown to same event
Anyway have a look to this, maybe can help...
https://blogs.msdn.microsoft.com/llobo/2009/12/07/wpf-touch-basics/
https://blogs.msdn.microsoft.com/jaimer/2009/11/04/introduction-to-wpf-4-multitouch/

Related

WPF Browser control Mousedown event not firing

I have a problem in my wpf project. I have a webbrowser control. What I want is to know whether anybody has clicked on the webrowser control. I used the mousedown event. But to my surprise it is not firing the event. In the webbrowser control I find that only Navigated and Navigating events are fired. Please let me know how can I get mousedown event? Thanks for your time.
Mouse events are not supported by the WebBrowser control. Please refer to the following (duplicate) question for more information about how you could solve this.
WPF WebBrowser Mouse Events not working as expected
MACMAN, add event handler manually, like this:
public MainWindow()
{
InitializeComponent();
AddHandler(FrameworkElement.MouseDownEvent, new MouseButtonEventHandler(WebBrowser_MouseDown), true);
ps: See this topic: https://social.msdn.microsoft.com/Forums/en-US/61807025-d4c4-41e0-b648-b11183065009/mousedown-event-not-working-wpf?forum=wpf
I got the solution by injecting javascript that adds a html mousedown event to the website. The javascirpt in turn invokes a wpf function that is written into a class using ComVisible[true].
http://sekhartechblog.blogspot.in/2012/04/webbrowser-javascript-communication-in.html

WPF window_loaded event triggered but window is not loaded

I have an problem. I have tabitems and if these items have images in the in the header, the window_loaded event is triggered before the window become visible. If the tabitems are just plain old tabitems, the window is visible before the loaded event. Does anyone know why is that happening?
As described here, I believe that you really should be using Window.ContentRendered instead of Window.Loaded
#StillLearnin thanks for pointing to the right direction.
Instead of using Window_Loaded event I used Window_ContentRendered

I cannot find the form.shown event handler

I am using Visual Studio 2012. I have added reference to System.Windows.Forms. But I cannot find Form.Shown event handler in the properties-eventhandler window.
Please help me.
Is there any alternative for the same?
When you are using WPF, you can not use WinForms. Those are not the same. You must use the Events from the Window class in WPF.
I assume you use WPF since the WPF tag is there.
For a WPF window I would use one of the following events:
Activated Occurs when a window becomes the foreground window.
GotFocus Occurs when this element gets logical focus.
Loaded Occurs when the element is laid out, rendered, and ready for interaction.
StateChanged Check if WindowState == WindowState.Normal
The WPF equivalent handlers you are possibly looking for are Loaded() and/or Activated(). You might also look at SizeChanged()

How to fire UIElement.TouchDown event on Windows Forms C# on Touchscreen, windows 8

This need to be Windows Forms (winforms) - not WPF. Problem is with single MouseDown event that didn't fire properly on touchscreen on windows 8. MouseDown fire either after touch and move finger or after click - it fire just after you get off your finger. I want to fire it like a normal MouseDown should - after i touch the screen. The solution to that would be that TouchDown event. But, i just cant to handle that event. What I do is that I create class Multitouch like that:
class Moultitouch : UIElement
{
public Moultitouch()
{
this.TouchDown += new EventHandler<System.Windows.Input.TouchEventArgs>(Moultitouch_TouchDown);
}
void Moultitouch_TouchDown(object sender, System.Windows.Input.TouchEventArgs e)
{
//it never goes in
}
protected override void OnTouchDown(System.Windows.Input.TouchEventArgs e)
{
base.OnTouchDown(e);
}
}
After that I'm declaring that class in my component which on Touch should handle that event. I did a lot of research on that and 've been trying to do that and nothing so far. I think that "Hosting a WPF Composite Control in Windows Forms" http://msdn.microsoft.com/en-us/library/ms742215.aspx could solve my problem but that solution could be really long and tough. Any help or ideas are really appreciated.
Your issue is that touchscreen fired events and mouse fired events are not the same thing. For example a Winform button can toggle its background colour by handling OnMouseEnter and OnMouseLeave. Code that up on a form and run the cursor in and out of the button and everything works fine. Use a touch screen and run your finger over it in the same way and nothing happens until you release contact with the screen, and then a click event is raised. Not the answer you are looking for, but I am having the same issue with an on-screen keyboard I'm developing for a disabled friend of mine. My research led me here https://blogs.windows.com/buildingapps/2017/05/25/uwp-evolution-touch-development/#02octDx0X3uBHXqm.97 and specifically to the links that provide detail on the ManipulationStarted and ManipulationEnded events. Hope that helps, it has for what I'm trying to achieve.

Button event on release

Im working on an app to control some stuff over bluetooth.
Currently I have a form with some buttons. On each button I want to trigger an event when the button is pressed down and fire a different event when the button is released.
Is this possible?
Not sure what the "bluetooth" info should tell me.
But in C# Winforms, yes that is possible. See the MouseDown and MouseUp Events: http://msdn.microsoft.com/en-us/library/system.windows.forms.button_events.aspx
(You may need to combine them with the keyboard events to capture them as well)

Categories