Posts

Showing posts with the label forms

[Xamarin Forms] XAML previewer in Visual Studio 2017 (really slow)

Image
Preview my Xamarin Forms XAML ? Today, I started a new Xamarin Forms application and for that I decided to use Visual Studio 2017 Community edition. Why ? Because I know that this version includes interesting features to me. One of this feature is that we can preview our Xamarin Forms XAML pages (theorically in a better way than in VS2015). First, we have to notice that to preview XF XAML pages, we don't use the exact same way as with  traditional XAML pages. In fact what we are looking for is not the designer but the Xamarin Forms Previewer Window . Take a look at the next steps to understand the differences...  There is not a lot of details on Xamarin Web site: https://developer.xamarin.com/guides/xamarin-forms/xaml/xaml-previewer/ XAML Designer vs Xamarin Forms Previewer On a XF XAML page, right click on the code: Using traditional "Designer menu" as for traditional XAML page We got an error Then use the previewer ( menu VIEW\Other Wi

Xamarin.forms.Maps - Tap to get a position on the map...

Image
Xamarin.Forms.Map component Xamarin.Forms.Maps is a great component. It gives you the possibility to deal with maps and geolocation problematics in a few lines of code. This "Map" component internally use native map controls for iOS, Android and Windows Phone: You can display and locate "Pins" with custom information on the map. I suggest you to read the reference links above. Display pins with custom information The problem But actually, in my mind, the Map control miss a very important feature: --> Tap  on the map to get the relative location (to put a new pin, to get the relative address...) The workaround Use renderers Actually, to solve this problem, we need to implement custom renderers for iOS and Android. Maybe this feature will be implemented later by Xamarin... So here is my solution (3 code files below): - ExtMap.cs : overloaded map control that will contain our "Tapped" event to get the tapped location

[Xamarin Forms] Embed custom fonts in your apps

Image
Recently I had some difficulties to embed custom fonts in my applications. Specially with the iOS application that was crashing with no message (while it was working for the Android version). In fact, it was a font issue. So in this post I will show you some tips to embed quickly custom fonts in both your Android & iOS apps. 1- Select your fonts The first step is to get some cool fonts you want to use. You'll maybe use (free) fonts from various websites like: www.1001freefonts.com www.dafont.com 2- Set font files properties In your solution, include your fonts files: iOS:  Create a subfolder (in the the 'Resources' directory) where to embed the fonts Build Action = BundleResource & "Copy Always" Android : Create a subfolder in the 'Assets' directory where to embed the fonts: Build Action = "AndroidAsset" & "Copy Always" 3- iOS application: edit your plist file With iOS you need to specify the e

[TIP] "Dispatcher.BeginInvoke()" in Xamarin.Forms

In traditional WP8 apps, when you want to update a visual element but you are not in the UI thread, you have to use the dispatcher like this: Deployment.Current.Dispatcher.BeginInvoke( /* my custom task */); In Xamarin.Forms, you have to use the Device 's object static method: Device.BeginInvokeOnMainThread(() => { // your code on UI thread here... });

Xamarin.Forms device unique ID...

As in a lot of applications, you will probably need to get a unique identifier to identify a unique user . And it becomes a little more complicated when you have to deal with different platforms like Android, iOS and Windows Phone... Here is a simple solution that you can implement in Xamarin Forms that I found on this blog: http://codeworks.it/blog/?p=260 First define a service that you will use in your Xamarin Forms Application: // Your service interface definition public interface IDevice { string GetIdentifier(); } // How you get your service in your app IDevice device = DependencyService.Get (); string deviceIdentifier = device.GetIdentifier(); And here are the implementations for Android / Windows Phone and the most complicated, iOS platform: // WINDOWS PHONE [assembly: Xamarin.Forms.Dependency(typeof(WinPhoneDevice))] namespace XFUniqueIdentifier.WinPhone { public class WinPhoneDevice : IDevice { public string GetIdentifier() { byte[] myDeviceId = (

Xamarin.Forms: Picker control and "Items" binding problem...

Image
If I tell you "ComboBox", you will see quickly of which control I'm talking about. There no control named "ComboBox" in Xamarin.Forms but if you search a little, you will find the "Picker " control. Class: Xamarin.Forms.Picker In the namespace: Xamarin.Forms Doc link : http://iosapi.xamarin.com/index.aspx?link=T%3AXamarin.Forms.Picker The problem is that you cannot bind directly "Picker.Items" property in the XAML file ! For that you have to use the code behind file. xaml (doesn't work): <Picker Items="{Binding MyViewModelList}"... /> So what do we have to do ? 1- Name your "Picker" control in the xaml file (by adding an attribute like x:Name="uiPicker" ) 2- On the parent page in code behind, override the "OnBindingContextChanged( )" method 3- In this method, fill your "Picker.Items" property from your viewmodel's values. 4- On the XAML file, you can onl