Need an if statement inside GotFocus event - c#

In my windows phone 7 application, i have created a grid(named as Holder), and i have created a GotFocus event. So i need an if statement that, if the grid is touched by the user, i need a message box to be didplayed. Can anybody help me? Thanks in advance for your help!
In my app, i have web browser control, in that if the user GotFocus on the browser control, then i want to hide an image. But Tap event is not working for the browser control. Need help?

The event you should use is the Tap Event, it's meant for user interaction on Windows Phone.
Hook up the event with your grid in XAML:
<Grid x:Name="Holder" Tap="Holder_Tap">
</Grid>
And in your code:
private void Holder_Tap(object sender, GestureEventArgs e)
{
MessageBox.Show("This message");
}

It's not equal to the GotFocus event, but I think this will fit your needs: use the Tap event, it will be fired when the user taps the grid.

Related

Holding event is not fired on touch screen device

I'm trying to create a simple uwp app where I require to display a context menu, if user right clicks on non-touch device and if user holds on touch screen device.
I'm using righttapped event which works perfectly on my desktop. The other side, I use holding event which should be triggered when screen is long pressed but it doesn't work(on touch screen mobile).
private void Webview_Holding(object sender, HoldingRoutedEventArgs e)
{
Webview.ContextFlyout.ShowAt(sender as FrameworkElement);
}
Do I need to use some other event for showing context menu, if yes then which one?
You should use RightTapped event for both touch and non-touch devices as I answered here. However, WebView does not support all of the touch or keyboard events.
Remarks section of MSDN for WebView control:
As indicated in the Events table, WebView doesn’t support most of the
user input events inherited from UIElement, such as KeyDown, KeyUp,
and PointerPressed. A common workaround is to use InvokeScriptAsync
with the JavaScript eval function to use the HTML event handlers, and
to use window.external.notify from the HTML event handler to notify
the application using WebView.ScriptNotify.

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

UWP Template10 SystemNavigationManager Back button adding GotFocus event

I am trying to to add an OnGotFocus event on Template 10 Back button as:
In PageViewModels.cs:
public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary<string, object> suspensionState)
{
SystemNavigationManager.GetForCurrentView().BackRequested += OnGotFocus;
}
private async void OnGotFocus(object sender, BackRequestedEventArgs e)
{
....
}
But that does not work. Can anyone give me any pointers?
What you did in your code snippet is that you wired up a handler for the BackRequested event. This event is fired when the system registers a request to go back in the app. This can be fired by the user tapping the back button in Task bar in Tablet mode on desktop, or by clicking the back button in title bar of your app in Windowed mode or pushing the back button on mobile device.
Either way, this event is fired by the system and the only thing it does is that it calls your method. The name of your method does not matter at all.
I think you should review some basics about event handling in C# to clear up any confusion.
To be able to use the OnGotFocus event, you will have to create your own back button in XAML and add the handler to this button, because only this way you have full control over the control. If you just use the system provided BackRequested event, the system is in control and apart from this event you can't customize anything.
<Button GotFocus="OnGotFocus" Content="My back button" />

What is the event which fires every time when i click outside for my wpf page?

i am developing windows application using wpf. I want to do some functionality when i click outside of my control created. for example, if i have Message-box open in my window, i want to do some function if i click outside of my Message-box window.
I tried,
private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
.....
}
but its not working.. please any one tell me, what is the event fire when i click outside of my control?
you have two supposed solutions:
one of them is to get Mouse.X, Mouse.Y from System not from application, this article will help
http://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C
second which is better is not using Dialog, but use PopUp window and this article will help
how to close a WPF Dialog Window when the user clicks outside it

How to bypass the enter/leave event in c sharp

I'm having a Picture box in a user control window(Windows custom control library). and some functionality in the Form's Enter event and leave event.
Now my sample application is having two instances of the control. So when i run my sample application the fist control got selected and the enter event is triggered, and when i select the second control the first's leave and second's enter events are getting triggered.
Now, problem is that when i select(click) the second control's picturebox, the events are not triggering, i.e the control form is not getting the event.
So if i click whereever in the control(in the picturebox or in the control) the enter event should be triggered.
How to do this?
A picture box can't get focus. So clicking on it won't take the focus away from the previous control thus not triggering the events.
You need to add a click handler on the picture box in which you manually give focus to the associated focusable control.
private void PictureBox_Click(object sender, EventArgs e)
{
focusableControl.Focus();
}

Categories