How to use a PIP mode in Xamarin.forms? - c#

Tap the video player to drop in to Picture-in-Picture mode. Tapping on the PiP view will present controls which can be used to pause, show info, return to full screen, or exit the application.

Xamarin.Forms by default only contains Views that work on all platforms. For example an Entry -> EditText (android), UITextField (iOS), TextBox (UWP).
The Picture-in-picture ability is something that's only available on Android, which means Xamarin.Forms did not implement this.
The only way i could think of doing this is by exporting custom renderers that set the native control for a home-made xamarin.forums-view. I think you can find a good example here: http://blog.infernored.com/going-native-using-android-views-in-xamarin-forms, though i haven't tried it myself.
You'd basically use the SetNativeControl command in the OnElementChanged hook of the custom renderer to probably dom.xamarin.PictureInPicture.MovieView. Don't forget to export the renderers on the namespace.
Then you can use the XF view on your xaml-pages. I'll look in to making an sample.
Picture-in-picture sample for android-only: https://developer.xamarin.com/samples/monodroid/android-o/PictureInPicture/

Related

How to implement Pointer-/MouseMoveEvents in Xamarin UWP app?

I have a Xamarin app. (Only) for the UWP app I need access to the mouse events (PointerMoved- / PointerEntered / PointerPressed-Events).
Until now my entire codebase is shared code.
Can somebody help me with forwarding the mouse events to the shared Code base? I googled a lot and nearly all answers either suggest a paid libary called "MR.Gestures" or say that it is not possible to recieve mouse Events (like this one I am not able to implement MouseUp, MouseDown and mouseMove Events in Xamarin Mobile applications). Sometimes GestureRecogniser are mentioned, but they Arent extensible, so how are they supposed to help?
Is there really no way to recieve mouse Events in xamarin?
You can do this. However it is a very extensive work to the level that you might consider to write your app in the native UWP XAML and share some C# code with the Xamarin project instead.
The way would be to extend each control that you are going to use (yes every single control that needs this effect), add to it those events and then write the UWP custom renderers that would invoke those events and then replace all controls in your XAML with those controls.
As said this may turn to be quite extensive work, but that's how it can be done.
Also if you don't need those events but just some visual effects on those events it may be possible to cut on this work by writing a custom XAML styles for those controls in app.xaml in the UWP project.

Getting Master Detail to behave on UWP just like it does on Android and IOS

I have a prism Xamarin Forms application which is being designed for both UWP, Android on IOS. This is the first UWP app that I have created. I want to have a menu that is only accessible from the first level of navigation. To do this, in the past, I have used a Master-Detail page. However, I have encountered some behaviour differences that I need some help with.
When I use a Master-Detail screen on IOS or Android it behaves like a menu only accessible to the first level of navigation. Any subpage that you might navigate from there you don't see menu it is replaced by the back button.
When I use a Master-Detail screen on UWP it's behaviour is different. The menu is available on all pages no matter how far into the navigation stack you travel. It is by default also a menu tray of items anchored on the left side of your application.
I have figured out how to make the menu collapse into the hamburger button that I am used to on an Android and IOS application by setting the parameter MasterBehavior to the value Popover. But I would like to have the menu completely disappear on any page navigated past the first level as it does on IOS of Android.
Does anyone know of a way to make this happen?
I think I can say safely that this can't be done in pure Xamarin.Forms.
To change this you would have to change to which UWP Frame the content is loaded, and I am not aware that Frame is exposed anywhere in Xamarin.Forms which means that even custom renderers cannot help.
However you may try to build the native navigation that would act like that in the UWP project and then load inside those native controls Xamarin.Forms page, that should work and deliver the results that you have requested. Not trivial and no few lines that I can show you, but if that is important for you it should be possible this way.

Implement swipe to delete for UWP

Is there a way to implement swipe to delete for UWP.
I have checked the documentation about implementing ContextActions, but this gives a context menu and not the swipe to delete behavior I am looking for.
Since UWP supports this natively, anyway to override the implementation of XF?
There is no built-in Xamarin.Forms control that utilizes UWP' SwipeControl control, but you can implement it yourself by creating either a custom renderer of an existing control (see documentation here) or a entirely custom view that is rendered as SwipeControl on UWP (see documentation here).

how to keep loader for xamarin c# while calling webservice

I wanted to keep loader for xamarin forms is there a way to keep loader in PCL file rather than keeping separately in android and ios
There are few options:
You can use ActivityIndicator which is an abstraction of a 'loader' on each platform. Just add <ActivityIndicator IsRunning ="true" /> to your XAML.
Another option is to use 'IsBusy' property of Page. So you could set it to true to activate global activity indicator on each platform.
Additionally, there is a very handy open source library Rg.Plugins.Popup which you can use to present an AcitivityIndicator as a popup, so you don't have to deal with disabling controls on your form.
Now when you know how to present a loading indicator on the screen, all you need to do is to bind 'IsRunning' (depends on the presenter) to a bool flag in your ViewModel.
Which will change its state according to your WebService call state.
Good luck.

Custom Toggle Button using c# code in xamarin forms

I need to create custom toggle button using C# code. Please refer below snap, it should act like a toggle button.
If you don't want to use the plugin, you need to perform custom rendering.
https://github.com/chrispellett/Xamarin-Forms-SegmentedControl
The above github repository has the source code for custom rendering for segmented button in andorid and ios only not for windows.
Take a look at SegmentedButtonGroup in FreshEssentials. It looks like that is what you need.
http://www.michaelridland.com/xamarin/freshessentials-for-xamarin-forms-the-must-have-nuget-for-forms/

Categories