I am new to Xamarin, but learning quickly. I have what is hopefully a straightforward question. I know that I can customize Xamarin Forms controls per platform using custom renderers, and I also know that I can use native controls that have 0-param constructors with dependency service.
my question is, how do I use a native control (specifically Android ImageView... and eventually obviously WinPhone and iOS counterparts) in my Xamarin Forms PCL app?
A very simple example would go a long way, since I'm just having trouble getting my head around how I would define an interface which would set parameters like buffering, image source, etc. on the platform-specific controls.
Thanks for your help!
With the latest update to Xamarin Forms this is a newly added feature.
You can read more about it in the blog - Embedding Native Controls into Xamarin.Forms.
Also you can find samples at Native Embedding - Adding Platform-Specific Controls to a Xamarin.Forms Layout
On Android, the following code example demonstrates how to add a TextView to a StackLayout and a ContentView:
var textView = new TextView (Forms.Context) { Text = originalText, TextSize = 14 };
stackLayout.Children.Add (textView);
contentView.Content = textView.ToView();
For this to work you have to use a Shared Project template and not PCL. For PCL you will have to use Custom Renders.
Related
I want to implement an ArcGIS web map in my winform C# application. I have found a bunch of resources for doing this in a WPF application, but nothing for the winform platform. I have an API-Key from ArcGIS and have already made a webmap.
Does anyone know if this is even possible or do I need to use WPF to do this? I have tried the GMap open source, and it does support some maps from ArcGIS, but I have not figured out how to add "custom" webmaps from a link. I would also need to add credentials to my example.
F.eks
Map.MapProvider = GMap.NET.MapProviders.ArcGIS_World_Street_MapProvider.Instance;
Edit,
Sadly it seems that the best solution is to implement a wpf controller into the winform application.
You can definitely use the Esri ArcGIS Runtime SDK to do this. Yes it is a WPF control, but that's no problem. You'll need to use the ElementHost to host WPF content inside the WinForms view, and this is fully supported but the runtime. Just be aware that WinForms uses software rendering, so you don't get as good performance as you would with a pure WPF, UWP or WinUI3 window.
So you'll just follow all the doc found on how to do it in WPF, then render that part of the view inside the ElementHost of your WinForms app.
WinForms Element host doc: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.integration.elementhost?view=net-5.0
Conceptual doc/examples of hosting WPF in WinForms:
https://learn.microsoft.com/en-us/dotnet/desktop/winforms/advanced/walkthrough-creating-new-wpf-content-on-windows-forms-at-design-time?view=netframeworkdesktop-4.8
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/walkthrough-hosting-a-wpf-composite-control-in-windows-forms?view=netframeworkdesktop-4.8
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/walkthrough-hosting-a-3-d-wpf-composite-control-in-windows-forms?view=netframeworkdesktop-4.8
/Morten Nielsen - Dev Lead (ArcGIS Runtime SDK for .NET)
If I understand correctly you want a world map, I don't know what you're planning on doing with it so if you just want to display a world map then I found a YouTube tutorial about this that might help,
https://www.youtube.com/watch?v=TxSJJfaAzKg
If you want an interactive map and arcgis does that for you then you can emulate a WPF control inside a winforms application,
https://www.youtube.com/watch?v=VfpzVDAJ1fE
Sorry if I'm only showing YouTube videos as sources instead of actual documentation, but at least it gets the job done.
I have a question surrounding the PCL. From all that I read up it is my understanding that you can only use Prism.Forms with PCL, when the views are in the portable library (ie. the xaml views and not in the native libraries). Am I mistaken? Is there a way to use prism with native layouts?
I want to use Prism in my xamarin app but I want to create native layouts for Android & IOS. But I cannot figure out how to make Prism navigate from page to page and how to tie the ViewModel to the layout as there is no AutoWireup option in the native.
So it seems that Prism is a xaml only option?
Prism for Xamarin.Forms (Prism.Forms.dll) only supports Xamarin.Forms. It does not support Native Xamarin iOS or Android.
Hi asked this same question on Brain Lagunas blog and he aswered me back:
Prism.Forms only worlks with Xamarin.Forms, it doesn’t work for Native Xamarin for iOS or Android.
Thanks Brain
We want to create an app, which works on multiple platforms showing a lot of lines and graphics. Since we have a Xamarin license and this app will not require any native look Xamarin.Forms is our choice. On the other hand we need mentioned graphics so we are thinking about using MonoGame (since we already know this framework). The only thing in here is, we would like to use some scrollviews in overlays and maybe the appbar (navigation bar on top). For this we had some problems in our test.
Now we are unsure what to use and would like to know if there are any other approaches to use Xamarin.Forms and OpenGL in parts.
Xamarin.Forms has a OpenGLView View and it can be used within a Xamarin.Forms page amongst other controls.
There is some examples, using Xamarin.Forms with this here.
Do note, however that this is only available in iOS and Android however.
Along with MonoGame, you have Urho which is mentioned on the Xamarin website that you may want to look into, link here. As to whether Urho is compatible with Xamarin.Forms I do not know.
I'm writing a UWP app, and for some reason I'm unable to reference PresentationFramework.dll. It contains some WPF controls I want to use (specifically, System.Windows.Controls.DataGrid, but they aren't available under Universal Windows >> Extensions in the reference manager. Why is this, and how can I fix it?
TL;DR: You can't use WPF controls in UWP.
WPF and UWP are two totally different APIs with a different .NET framework. While WPF has access to the full .NET Framework, UWP has a much more limited API. If you want to read more on the different platforms and compilers, this msdn blog post is a good entry point.
You are thus unable to add any standard dlls as a reference to an UWP app. If you want to share code between WPF and UWP, you'll have to use a Portable Class Library, in which you target the platforms you need.
And as the XAML namespaces for WPF and UWP are different as well, you won't find many portable controls. So for UWP development you'll need to use UWP controls (equivalent to their WPF counterparts). Bonus tip: if you're looking for 3rd party controls, you can also look for 'winrt' controls as winrt was used for Windows 8/8.1, but it's the same technology.
I know this is an old question. Not even going to research what came out when. There is a DataGrid for UWP as part of the community toolkit:
https://learn.microsoft.com/en-us/windows/communitytoolkit/controls/datagrid
It's really frustrating though, because it doesn't seem to do a few things that the WPF version does, and these are the few things I needed it do do.
Microsoft really needs to come up with a new naming conventions for its 114 different frameworks and platforms. Controls should be named DataGridWpf, DataGridUwp, etc.
It's super hard to search for examples of the UWP DataGrid control and find thousands of examples for the WPF version. Just my two cents. And for the record, it seems like there are about 5 active links to examples on the UWP version. Arrg.
/And for added fun, Telerik and DevExpress have UWP data grid controls, which they also call DataGrids.
I have followed this article here:
http://blogs.msdn.com/b/eternalcoding/archive/2013/10/29/how-to-use-specific-winrt-api-from-desktop-apps-capturing-a-photo-using-your-webcam-into-a-wpf-app.aspx
And it all works great... but how do I get a preview in WPF?
The XAML "CaptureElement" control is not available in WPF. Is there any other way I can get a preview using the MediaCapture API?
Why would Microsoft not make this control Available?
Late reply, but in case that helps folks in the future: previewing MediaCapture in WPF is difficult but possible. Here is some code sample:
https://github.com/mmaitre314/MediaCaptureWPF
After investigating further it seems impossible to get this to work with the XAML Capture Element or any other XAML element in WPF.
I decided to port my WPF app to a Win8 application. I kept the existing back end code and referenced it using a Brokered WinRT Component. An excellent tutorial can be found here: http://devhawk.net/2014/04/25/brokered-winrt-components-step-one/ on how to create a WinRT brokered component.
Keep in mind that the app must be sideloaded and will not work for apps that you want to publish to the store.
You will have to rig up a mechanism to display the converted BitmapImage yourself, e.g., either in an Image control or as an ImageBrush on some surface. To the best of my knowledge, WinRT controls cannot be hosted in WPF.
CaptureElement was presumably not ported to WPF because it depends on WinRT APIs, and it makes little sense to introduce a dependency into WPF for an API that is only available on Windows 8+, and which is only officially supported in Windows Store apps.