How can i capture a global touch event? - events

i have a Xamarin application in UWP that has multiple screens which build up while being used. on each screen there are multiple controls in which they can enter information. what i am trying to do is - if the screen has not had any interaction in the way of a touch / click from the user then to time out and go back to the beginning. i can of course capture the event of each control that has been touched and reset but i was wondering if there is like a 'Global' touch event that will fire when the screen is touched.

if there is like a 'Global' touch event that will fire when the screen is touched.
Sure, For UWP you could add PointerEntered event handler for current CoreWindow and it is Global on the top level. Please refer the following steps.
public MainPage()
{
this.InitializeComponent();
Window.Current.CoreWindow.PointerEntered += CoreWindow_PointerEntered;
}
private void CoreWindow_PointerEntered(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.PointerEventArgs args)
{
// do some stuff
}

Related

VSTO Outlook: Handle event when custom task pane changes its height

The custom task pane has a down arrow button at the top right corner which if you click on it a contextual menu appears showing two options:
Resize
Close
I would like to handle the event when user resize the height of the custom task pane and gather the height set by the user. Is that possible? if so, how? what event do I need to handle?
Your task pane is a user control where you could override methods in the following way:
protected override void OnSizeChanged(EventArgs e)
{
// this.Size
base.OnSizeChanged(e);
}
Don't forget that you could also override the windows procedure which processes Windows messages - WndProc, where you could detect such actions like closing (see WM_CLOSE).

Xamarin Mac minimize to tray on close button

I want change behavior of standard close button of window. When user clicked on it then minimize to tray, not close window. How can I do this?
P.S Here is a small video example of this behavior on Slack application. I want do same.
Override the applicationShouldTerminateAfterLastWindowClosed method in appdelegate like:
public override bool ApplicationShouldTerminateAfterLastWindowClosed(NSApplication sender)
{
return false;
}

What happens in the OnAppearing of Xamarin Forms?

I have a Forms application which works good but I notice the background colors appear set incorrectly for a fraction of a second as the page appears.
I have this code for my OnAppearing
protected override async void OnAppearing()
{
base.OnAppearing();
Subscribe();
vm.Theme = Settings.th.ToString();
await SetCardButtons(Settings.cc.Text());
}
Can someone explain what happens in the base.OnAppearing() and should this be the first or last line in my override?
what happens in the base.OnAppearing()
OnAppearing is a virtual method in the Page base class, that does not contain any code (but that does not mean it does not do anything).
Depending upon which Page subclass you are using, different things might be performed, like the MasterDetailPage performs logic to determine if it should be displayed as a splitview (side-by-side) mode, the native iOS code would do this on an iPad, ....
should this be the first or last line in my override?
Normally this would be called first in your override to allow any custom subclass code to setup the UI properly.

Is there an event name for this action?

Is there a ScrollView event in xamarin that is triggered when the user forces scroll up and scroll is already at top? Many apps uses this as the "command" to update the page.
Currently, there is no PullToRefresh property or RefreshCommand for a ScrollView built into Xamarin.Forms. However, It does exist on ListView as shown in the docs, which you might be able to use instead depending on your needs.
Also, it does look like there is a PullToRefreshLayout opensource project created by James Montemagno you might be able to use to easily implement pull to refresh with a ScrollView, but it has been a while since it's last been updated.
You can use the Scrolled event handler. If the ScrollView is already positioned at the top of the contents and the user "pulls down" then Y amount will be either 0 or negative (I know this will work on Android and iOS, not sure about UWP and others).
scroll.Scrolled += (object sender, ScrolledEventArgs e) =>
{
if (e.ScrollY <= 0)
{
// scrolled when already at top of list
}
};

Detecting plug/unplug of headphones in wp7

Is there a way to detect when a user pluggs or unpluggs the headphones on wp7?
The problem is that when a song is playing on a background AudioPlayerAgent and the user plugs on unplugs the phones, the protected override void OnUserAction method of the AudioPlayerAgent receives a pause UserAction and pauses the music.
I need to detect the plug/unplug on the UI thread so I can update the GUI to reflect a paused state.
You need to subscribe to the PlayStateChanged event of the BackgroundAudioPlayer within your page:
public void MainPage()
{
InitializeComponent();
BackgroundAudioPlayer.Instance.PlayStateChanged += InstanceOnPlayStateChanged;
}
private void InstanceOnPlayStateChanged(object sender, EventArgs eventArgs)
{
// Update UI
}
I don't believe there currently is any API to query the current state of the head phones.
You might be able to hack a solution to your problem using the Media element. The Media element will raise an CurrentStateChanged event whenever the headphones are unplugged, so you might be able to hook up on this event to change the state of your GUI. It's not the most elegant solution, but it might but the only way at the moment.

Resources