I'm developing a Xamarin Forms application and I have implemented an IOS custom renderer for a content page.
I generate the page from laying out the native controls programmatically where ListEntry is a subclass of UITextField.
ListEntry entry = new ListEntry(control, new CGRect(x, y, width, height));
entry.BackgroundColor = UIColor.Blue;
view.AddSubview(entry);
I have been using two way data binding to hook up my Xamarin Form content pages to view models but I'm not sure how I go about doing this with custom renderers and native controls. I'm looking for a little guidance on the best way to approach this?
Thanks
Related
Is it possible to add "SwapChainPanel" view to Xamarin forms?
i have tried to use custom renderer but no success with that.
what i did:
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
I'm pretty new to Xamarin Forms and C# in general, and need som hints on the best way to create an app for iOS and Android. I want to use the Camera to take pictures / videos and later on send them with email or something else, since I want customized controls on the camera, I'm guessing the stock camera won't be an option? Which gets us to Renderers, which is the best approach to this? Preferably in a MVVM way. I just want the camera and a few customized buttons on it.
Do I make on renderer for the different buttons objects and one for the camera, the buttons I'll do as extensions of the Button class, but what about the camera?
/Oliver
You have two options:
Create a page renderer and put your camera/buttons native in each platform.
Create a view renderer for the camera and add your view in any page of Forms, so you can put your buttons or anything you like in forms.
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.
I have a Xamarin.Forms page with a map containing numerous pins. I've built a custom iOS renderer to change the image of the displayed pin.
Once I assign the GetViewForAnnotation delegate, my Xamarin.Forms class no longer receives the "Clicked" event. I can access it through the custom renderer, I do believe, but what I want to do when the user taps the title of the pin is push another Xamarin.Forms page to the navigation stack, and I don't know how to give control back to my Xamarin.Forms app from within my Xamarin.iOS app.
I have a feeling I'll need this type of logic in a few other places... where I need to handle a CustomRenderer event but then pass control back to the Xamarin.Forms app for navigation or other purposes.
So I have a couple directions I'd like to go:
1 - More straightforward - get my "Clicked" event to fire in the Xamarin.Forms app when the map's pin is clicked, even though the iOS app is handling the creation of the pin via a CustomRenderer
2 - More advanced and customizable - pass control back to my Xamarin.Forms app (maybe raise an event related to the Renderer level?)
I'd prefer at this time to just get my Clicked event back, but I'm guessing that may not work once I assign the GetViewForAnnotation event in the CustomRenderer.
From what I read, you can detect the annotation click within your renderer.
Within your renderer in the OnElementChanged you can get access to the View in the Xamarin.Forms PCL it relates to.
A few possibilities to consider going forward:-
a) Use MessagingCenter to convey messaging between interests (see
here).
b) Use the standard event raising, i.e. public event
EventHandler<someEventArgs> OnSomeEvent through your View in your
PCL.
c) Use an ICommand approach on your View in your PCL if your
more MVVM orientated, and invoke this way instead.
Once you have your notification back through your View / Page, depending on where your doing things, you can then do a normal navigation based on the information you have been given from your platform-specific renderer in the PCL.