How can I get current view/layout in Android Xamarin by CustomMapRenderer class? I want to add view in current layout at specific position.
In iOS I am doing it by following lines:
UIView XView;
XView.Frame = new CGRect(50,50,40,40);
Window.AddSubview(XView);
Which View, specifically, are you after? The Xamarin Forms Map itself? Its container? The underlying native Android Control?
If you're after the native control, you have a reference to it in the Control Property of your renderer.
If you're after the Xamarin Forms wrapper for the native piece (a Map in this case), then you want to use the Element property of your renderer.
Both have a Parent property and the Element has a ParentView property.
Related
I'm working on a xamarin PCL project and I want to implement a print function.
In my shared code, I have a grid that contains a content view. the content view contains another grid with a custom list that contains data I want to print. as a toolbar item, i have a print button that calls in a dependency service but I don't know how to implement a print functionality for xamarin PCL content views.
The main platform is up.
Any help?
I'm working on a xamarin PCL project and I want to implement a print function. In my shared code.
You could implement a print function via DependencyService for per platform. And invoke the unified interface in your xamarin PCL project.
For the interface implementation about per platform, you could refer to the following document.
Android:Native Printing with Android.
IOS : IOS Print Sample. UWP: Print case.
any idea how I can start a native UWP page from a Xamarin Forms page?
The reason why I'm asking:
I have a XF application that needs to start a UWP library after a click event.
This library provides a special ORC reader.
Therefore I created a dependency service to run the platform specific function.
What I need now, is to open that UWP page, that contains the "Camera stream" to show the user what he is currently scanning.
And this is where I am hanging at the moment.
In my class that is called from the dep. service, I
myPage mp = new myPage();
But how can I show the new page?
Frame fr = Window.Current.Content as Frame gives me the error, that this page cannot be converted from a XF Frame to a Window Frame.
Or is there generally another way to handle this? Some advice would be great.
This sounds like a custom renderer.
Create a new OcrView class in your shared project inherited from View.
Place it on your Xamarin Forms XAML page.
Handle the OCR component in the UWP renderer.
Have a look at the Implementing a View section on this custom renderer overview
We are trying to present territory map view with different controls in android and iOS platform using xamarin.forms or Xamarin Native. Is there any map control avaialble to present territory map view in xamarin forms?
It looks like Syncfusion has something similar to what you want in their Maps
Is it possible to get Android.View (and equivalent view object in iOS) from Xamarin.Form.View? I have custom control which takes dependencies to Android.View. I am writing custom renderer which would set that custom control as native view but I need to convert my ContentView (exposed as BindableProperty, initialized in xaml) from Portable library to Android.View.
Yes you can. I have written an extension that uses reflection to get the underlying native view:
https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/src/Forms/XLabs.Forms.Droid/Extensions/ViewExtensions.cs#L54-L59
Native view in the code is Android.Views.View type and View is Xamarin.Forms.View.
https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/src/Forms/XLabs.Forms.Droid/Extensions/ViewExtensions.cs#L19
The same works for iOS as well, just cast it to UIView.
I'm trying to add a Xamarin.Forms page to an existing Xamarin Android app.
I'm struggling to figure out how to mix native Xamarin Android pages and Xamarin.Forms pages.
All the articles and examples I have seen describe either Forms or Xamarin apps and not a hybrid of the two.
The best idea I have read about so far is to add a native stub and replace the content with Xamarin.Forms content but I'm not sure how to achieve this.
Update
I'm using MvvmCross so my android view is inherited from MvxActivity. I have a StackLayout containing views using Xamarin.Forms. How do I get XF to convert to android code so I can use with SetContentView?
When you create a new Xamarin.Forms project, for instance with a SharedProject approach, it will create the launcher project and initial class file that will be executed for you for each platform.
For instance on Android this is in MainActivity.cs. If you look inside this file you will notice that it inherits from AndroidActivity which in turn inherits from Activity, which is the typical class used on activities.
So you have two options available for you to create a mixed hybrid solution:-
1) Inherit from AndroidActivity in your platform-specifc stub-page should you want to display Xamarin.Forms content, or alternatively
2) Inherit from Activity, and do the same as usual.
If you want to display a Xamarin.Forms page from the stub-page you can then just use some boiler-plate code such as the following in the OnCreate method:-
SetPage({some class that returns a Xamarin.Forms.Page object, i.e. ContentPage});
You can then use the normal navigation that is specific to Android to either display a Xamarin.Forms page or a platform-specific Activity page.