I have been working on an application that uses both forms and native in Xamarin. The app starts with the form and switch to native to open the camera. My problem is once the image is clicked I want to go back to Forms application but I am unable to find enough documentation on it.
I have tried Navigation.PushAsync in iOS but it doesnt work.
var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
var sampleBuffer = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);
var jpegImage = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);
var photo = new UIImage(jpegImage);
byte[] data;
NSData imageData = photo.AsJPEG();
data = new byte[imageData.Length];
EnrollImageDisplay.ImageData = data;
Where EnrollImageDisplay is my content page in forms. Not I have to call this page but I am unable to do so. Any solution with this?
EDIT: Solved it using Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new Page());
Related
I'm trying to create dialog with a custom layout view and when I try do this:
import app = require('application');
import { GridLayout } from 'ui/layouts/grid-layout';
const dialog = new android.app.AlertDialog.Builder(app.android.currentContext);
const layout = new GridLayout();
dialog.setView(layout);
So I got the following error:
Uncaught Error: Cannot convert object to Landroid/view/View;
I tried change to:
dialog.setView(layout.android);
And
dialog.setView(layout.nativeView);
And the dialog is displayed empty.
How I can convert a NativeScript UI Object to a native android View?
you can't access nativeView or android property of nativescript view without adding it to Visual UI tree. when nativescript view is added to UI tree then it gets valid values for android and nativeView.
so you have to do something like this:
let container= <StackLayout>this.page.getViewById("stackContainer");
let layout = new GridLayout();
let label = new Label();
label.text = "Custom Alert working";
layout.addChild(label)
container.addChild(layout)
now you will have values for android and nativeView properties of GridLayout.
but after that you will not be able to use layout.android or layout.nativeView in setView because it already contains parent. so workaround for this that you remove this view from container's native view.
let nativeView=layout.nativeView;
container.nativeView().removeView(nativeView)
dialog.setView(nativeView).show();
also note that removing child from container will also reset child's android property to null. that's why we are saving reference to nativeView variable.
here is working playground demo is you need help:https://play.nativescript.org/?template=play-ng&id=4610ET
(using PCL project)
I am using version 2.1 of the SignaturePad and works perfectly on Android, but on UWP, when I call the GetImageStreamAsync method, I get a 'Microsoft.Graphics.Canvas.CanvasDevice is not registered' error. I have tried both PNG and JPEG and both give the same error.
I was thinking something needed to be included in App.xaml.cs but looking at the samples, I don't see anything. I did find a post where they added the assembly
List<Assembly> assembliesToInclude = new List<Assembly>();
assembliesToInclude.Add(typeof(SignaturePad.Forms.SignaturePadCanvasRenderer).GetTypeInfo().Assembly);
but I still get the same error.
Here is the code that I am using:
SignaturePad.Forms.SignaturePadView SignPad = new SignaturePad.Forms.SignaturePadView()
{
StrokeWidth = 3f,
StrokeColor = Color.Black,
BackgroundColor = Color.White,
HeightRequest = 200,
WidthRequest = 400
};
// This gives error in UWP, but not Android:
var image = await SignPad.GetImageStreamAsync(SignaturePad.Forms.SignatureImageFormat.Png);
I've been working on this Xamarin Forms mobile application and I've been loving it but it's a media player application and the native embedding for the platform specific video player doesn't work. After much debugging I was able to get the audio playing but no video would show up. I think this has to do with the views just not being swapped out appropriately. Unfortunately there isn't much material on how to effectively switch from a Xamarin Forms view to a native view (to see the video) through Xamarin Forms. Any help is appreciated thank you !
I was able to get iOS videos working by using the Xamarin Forms messaging service to Appdelegate class and built the AVPlayer class there. Works great.
playVideo.Clicked += (sender, e) =>
MessagingCenter.Send(this, "ShowVideoPlayer", new
ShowVideoPlayerArguments(videoUrl));
Appdelegate.cs
MessagingCenter.Subscribe<VideoDetailPage,
ShowVideoPlayerArguments>(this, "ShowVideoPlayer",
HandleShowVideoPlayerMessage);
//messaging center class
private void HandleShowVideoPlayerMessage(Page page,
ShowVideoPlayerArguments arguments)
{
var presentingViewController = GetMostPresentedViewController();
var url = NSUrl.FromString(arguments.Url);
var avp = new AVPlayer(url);
var avpvc = new AVPlayerViewController();
avpvc.Player = avp;
avp.Play();
presentingViewController.PresentViewController(avpvc, animated: true,
completionHandler: null);
}
private UIViewController GetMostPresentedViewController()
{
var viewController =
UIApplication.SharedApplication.KeyWindow.RootViewController;
while (viewController.PresentedViewController != null){
viewController = viewController.PresentedViewController;
}
return viewController;
}
However.. Getting this to work with Android is a whole different animal since I have to have deal with .axml layouts I believe.. Any help with this would be greatly appreciate.. Thanks so much guys.
So I figured out an implementation using Native Views, an alternative to Custom Renderers. Such a more stream lined process.
I'm very very new to using Xamarin forms. So new in fact I have just watched the "microsoft xamarin forms for absolute beginners".
I'm trying to include a webpage into the Xamarin form but the only info I can find is
var browser = new WebView {
Source = "http://xamarin.com"
};
This might sound silly but has anyone got a full tutorial on how to include one?
thanks
just create a WebView and assign it to a ContentPage. Then you can either make this page the main page of your app (in the App class) or you can navigate to it from another page.
ContentPage page = new ContentPage {
Content = new WebView { Source = "http://xamarin.com" }
};
To display a website from the internet, set the WebView's Source property to a string URL:
var browser = new WebView
{
Source = "http://xamarin.com"
};
see this:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/webview?tabs=windows#performance
I am implementing a Universal Windows Application on Windows 10 using MVVM.
I have a file picker allowing me to choose an image. This image is displayed in an Image Control. The source of the Image Control is bound to a property in my view model. This property is a byte array. I need a converter to convert the BitmapImage in a Byte Array.
I have read lots of things but can't found something working.
I have found interesting stuff on https://writeablebitmapex.codeplex.com/
but if i want to use this package i need a WriteableBitmap and not a BitmapImage.
Thank you in advance for your help.
You can load the image to a WriteableBitmap object straight from the file.
var filePicker = new FileOpenPicker();
filePicker.FileTypeFilter.Add(".jpg");
var result = await filePicker.PickSingleFileAsync();
if (result != null)
{
using (IRandomAccessStream stream = await result.OpenAsync(FileAccessMode.Read))
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
WriteableBitmap bmp = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
bmp.SetSource(stream);
// show the image in the UI if you want.
MyImage.Source = bmp;
}
}
This way you have the WriteableBitmap and you can use the WriteableBitmapEx library.