How to handle/capture a long press in windows store apps - windows

Could anyone tell me how to capture a long press for a windows store app in C#?
I can used a "tapped" gesture no problem but when I replace
TappedRoutedEventArgs with HoldingRoutedEvent it just doesn't register a holding gesture.
I'm testing this with my laptop so could it be that it doesn't recognize a mouse holding event?
I'm assuming there's similar functionality for the windows phone 7 but they're mostly for Silverlight which isn't used for Windows 8.
Any links/examples would be a great help!
Thanks!

Use the Holding Event:
XAML:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" Holding="Grid_Holding_1">
</Grid>
CS:
private void Grid_Holding_1(object sender, HoldingRoutedEventArgs e)
{
Debug.WriteLine("You held at" + DateTime.Now.ToString());
}
You are correct about the mouse not firing the holding event. Run it in the simulator and then you can use the "Basic Touch Mode" to simulate the hold.

Related

What is the preferred way of interacting with Lottie files in a .NET MAUI app?

I would like to implement an animated Play/Pause button in my .NET MAUI streaming app.
For this I thought I might use a lottie file.
I am able to use SkiaSharp.Extended.UI.Maui to load and animate a lottie file.
However, the control itself does not offer any kind of interaction such as Commands or an OnClick event handler.
Maybe I am blind, but what is the preferred way of transforming this "static" control to something, my users can interact with?
If you want to provide some interactions, i thought you could add some gestures on SKLottieView.
In .xaml file
<skia:SKLottieView
x:Name="myanimatedview"
Source="dotnetbot.json"
HeightRequest="300"
WidthRequest="300"
RepeatCount="-1">
<skia:SKLottieView.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
</skia:SKLottieView.GestureRecognizers>
</skia:SKLottieView>
In .cs file, implement the event handler.
void TapGestureRecognizer_Tapped(System.Object sender, System.EventArgs e)
{
Console.WriteLine("hello"); // do whatever you want here
myanimatedview.IsAnimationEnabled = !myanimatedview.IsAnimationEnabled;
}
You could add different gestures, such as pinch, pan, swipe etc, to interact with users. For more information, you could refer to Xamarin.Forms gestures.
Hope it works for you.

How to add Share button to the CommandBar of a Windows 10 Mobile UWP App and sharing capabilities to it?

I'm trying to add a button to the command bar of a phone app (8.1 and UWP) with a typical Windows Phone share icon. How do I add such an icon to it?
I'd also like it to bring up the sharing window where the user can select the different ways of sharing something. It would share the link to my app in the store, like from the store app.
1: There is no share charm in Windows 10. What you can do is that you do the icon yourself. This would make it:
<AppBarButton Label="Share" >
<AppBarButton.Icon>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
</AppBarButton.Icon>
</AppBarButton>
2:
In UWP I would use Share contract. (Basically the DataTransferManager class…)
Here is a good documentation for that:
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/mt243293.aspx
Basically:
Hook up the event (e.g. in your page’s constructor..):
DataTransferManager.GetForCurrentView().DataRequested += MainPage_DataRequested;
Show the UWP share UI (e.g. on the button’s event handler..)
DataTransferManager.ShowShareUI();
Do the sharing:
private void MainPage_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
args.Request.Data.SetWebLink(URI);
args.Request.Data.Properties.Title = "My new title";
args.Request.Data.Properties.Description = "description";
}

Windows Phone Toolkit in XNA/XAML hybrid project hangs application

Using any control from Windows Phone Toolkit in XNA/XAML hybrid project hangs application under certain conditions:
Create "Windows Phone XAML and XNA App" project
Add Silverlight for WP Toolkit by typing:
Install-Package SilverlightToolkitWP -Version 4.2012.6.25
in Package Manager Console
In MainPage.xaml add toolkit namespace:
<phone:PhoneApplicationPage
...
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
...>
Add any control from toolkit eg. TimePicker:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<!--Create a single button to navigate to the second page which is rendered with the XNA Framework-->
<Button Height="100" Content="Change to game page" Click="Button_Click" />
<toolkit:TimePicker />
</Grid>
Run app on WP8 device or WP8 emulator (on WP7 this problem doesn't exist)
Click "Change to game page" button
Lock and unlock screen or switch to another app then return.
Click back button to return to MainPage
Click on TimePicker and try to change time.
Application isn't killed but UI is blocked
I read that WP8 runs WP7 apps in 100% compatibility but it seems this isn't true...
I finally found the solution for this bug! It's very easy to fix but was difficult to discover. Here's the line of code you have to add to your game page class in OnNavigatedFrom(NavigationEventArgs e) method. You have to add this if statement:
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
// Stop the timer
timer.Stop();
// Set the sharing mode of the graphics device to turn off XNA rendering
if (e.IsNavigationInitiator)
SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(false);
base.OnNavigatedFrom(e);
}
That's not the right version of the toolkit for WP8. As of now you should use https://nuget.org/packages/WPtoolkit (October 2012 version, version 4.2012.10.30)

windows phone 7 equilvalent of android's progress dialog?

In android there is a progress dialog class??
ProgressDialog dialog = ProgressDialog.show(MyActivity.this, "",
"Loading. Please wait...", true);
Use the ProgressIndicator
<shell:SystemTray.ProgressIndicator>
<shell:ProgressIndicator IsIndeterminate="True" IsVisible="True" Text="Click me..." />
</shell:SystemTray.ProgressIndicator>
There is ProgressBar control comes with SDK, also PerformanceProgressBar in Silverlight Toolkit exists (a little bit better).
In WP7.1 you have an access to SystemTray. It has an option to show that some actions happen (indeterminate or in percents) with additional message if you want

How to simulate the hardware shutter button in the Emulator?

In addition to soft keys, I'd like to test how my app responds to the hardware shutter buttons (e.g. various states half-pressed, fully-pressed, button-release. etc...).
The emulator does not seem to have a hardware shutter button (unless I am missing something).
So, in the absence of an actual device, how can I test this functionality?
The F7-Key is mapped in the emulator to the camera shutter-key fully pressed and the F6-Key is mapped to the half-pressed shutter-key.
Both shortcuts are not supported in Visual Studio 2010 Express for Windows Phone (but I have no idea why they did this limitation...)
http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff754352%28v=vs.105%29.aspx gives a list of supported emulator hot-keys. :)
You could have specific buttons in your application and simply invoke the method wired to the event handler. For example:
// Constructor
public MainPage()
{
InitializeComponent();
CameraButtons.ShutterKeyHalfPressed +=new EventHandler(CameraButtons_ShutterKeyHalfPressed);
CameraButtons_ShutterKeyHalfPressed(this, new EventArgs());
}
void CameraButtons_ShutterKeyHalfPressed(object sender, EventArgs e)
{
Debug.WriteLine("HALF_PRESSED");
}
But that would only help if you are willing to have a dedicated "test panel" in your application that will control these events.
As with everything else hardware related, you kinda can't ;-) So hurry on the mailman to deliver your phone already!

Resources