Posts

Showing posts with the label XAMARIN FORMS

[XAMARIN FORMS] Background task for 'closed' applications

Image
Background task for 'closed' applications Handling a background task in Xamarin Forms, even when the application is closed, can be challenging due to the mobile operating systems' restrictions on background activities. Here's a detailed solution using a combination of Dependency Service , Background Services , and Platform-Specific Implementations . Step 1: Create an Interface First, create an interface in your shared Xamarin Forms project that defines the method for starting the background task. public interface IBackgroundTask { void StartBackgroundTask(); } Step 2: Implement Platform-Specific Services Android Implementation: In your Android project, create a service that implements the IBackgroundTask interface. Create a Service: [Service] public class MyBackgroundService : Service { public override IBinder OnBind(Intent intent) => null; public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId

[Xamarin Forms] Complete guide to design a TOAST component

Image
  [Xamarin Forms] Complete guide to design a TOAST component In this guide, we will first show you how to design a toast component in Xamarin Forms (adding transition animations to the component), then in a second part, we list some existing controls that you can use directly... Custom Toast design in Xamarin Forms  Designing a "toast" component in Xamarin Forms involves creating a custom control to display brief messages to the user.  I will show you bellow a simple example on how to create a Toast component, and we will also how to add transition animation. Here are the steps to design and implement a toast component: Step 1: Create the Toast View First, you need to create a custom view that represents the toast message. You can add all the UI controls that you need to fit your needs (like an icon image...) 1.1 Create a ToastView class Create a new class ToastView that inherits from ContentView . public class ToastView : ContentView { public ToastView ( string m

XAMARIN FORMS TIPS: iOS 15 Transparent TabBar and Safe Area

Image
  iOS 15, transparent TabBar Since the release of iOS 15, some people had regression with their app, particularly because of the TabBar component . In iOS 15, by default (while using Xamarin Forms), the TabBar comes with a Transparent background and the page's content can scroll behind this TabBar. So it's not user friendly  and I presume for all existing apps, it's not beautiful. See the next picture: iOS 15, transparent TabBar You can solve this problem by many ways, but the fastest solution / workaround that I found is the following: => manage iOS SafeArea directly into your XAML to constrain page's content to fit the free space of the page.  You can do that in XAML in 2 lines of code: <?xml version="1.0" encoding="UTF-8" ?> <ContentPage xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" ios:Page.UseSafeArea="True" ... iOS 15 using Page.UseSafeArea = true As Ta

FFImageLoading - display pictures stored in shared assembly

Image
I already talk about the really convenient and powerful lib FFLoadingImage for Xamarin Forms (here: FFLoadingImage for Xamarin Forms (quick overview) ).  This library gives you a lot of tools to display and manage your application's pictures. Loading pictures from a shared assembly You can load pictures from different sources like:  - an HTTP Url  - An iOS or Android embedded resource picture. In this case you will need to duplicate the pictures for each specific platform project.  But did you know that you can also load images from a custom assembly like a SHARED Xamarin Forms assembly ?  It's pretty simple: Set your picture's build action to: Embedded Resource Shared assembly containing your pictures Picture's build action: Embedded Resource Then use the following syntax In your xaml file where you want to display the picture, just use the following syntax. FFLoadingImage library will do the rest to load and display correctly images for each native platforms:

Xamarin Forms + Installing Firebase plugin = errors

Image
[Xamarin Forms Shell App + Firebase iOS Auth plugin v. 6.9.2] Last day I added the Google Firebase functionalities to my project, but unfortunately I add some errors just after installing the Firebase Plugin. > Xamarin Forms (Shell app) + iOS Firebase errors adding latest package: ....iOS/MTOUCH: Error MT5210: Native linking failed, undefined symbol: _GULIsLoggableLevel. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. (MT5210) (*.iOS)  I found some solutions, and finally the iOS SDK worked with my Xamarin Forms Shell app... Unfortunately, with Xamarin Forms, we still take too much time to solve this kind of problem.  What did I do ? iOS project properties => Set the "entitlements file property" to a default file (the *.plist file can be empty): => iOS Build options: - Add 'mtouch' argument: --registrar:static - and try to set linker behavior to SDKs only Then initialize Firebase in your code:

EMGU with Xamarin Forms guide [part 1]

Image
I- Introduction, OpenCV and EMGU Do you know OpenCV ( Open Source Computer Vision Library:  https://opencv.org/ ) ?  This open source library let's you work and play with images and videos with a lot of powerful image processing algorithms !  If you want some details, I suggest you to first navigate to the link above or search for 'OpenCV' on Google.  Examples of OpenCV processing found on the web (filters, object detection, edges...): EMGU is a .NET OpenCV wrapper. That means that you will be able to use OpenCV functionnalities in your .NET projects using C# for instance. EMGU is cross platform, so you will also be able to use it in your Xamarin projects ! That's great because there is no advanced image processing library in Xamarin. In this article, we will talk about EMGU and list the steps to setup a Xamarin Forms project using EMGU . It may help you because, we must say that it's not a trivial task...  II-What do I need to

Xamarin Forms essential: FFImageLoading, manage your images

Image
Discover 'FFLoadingImage' library Today I want to make a quick presentation of a really good library for Xamarin Forms . This is the kind of library we would like to see more often on XF... This one is dedicated to image manipulation. It's called " FFImageLoading ". If I take time to make this presentation, it's because I think that we should use it in almost all our "basic" Xamarin Forms applications. When I say basic, I exclude Games or other specific apps. But in my mind, I suggest you to change all your traditional "<Image />" by "<FF:CachedImage />" in your apps. Before to start, where to find it ? On Github:  https://github.com/luberda-molinet/FFImageLoading On Nuget:  https://www.nuget.org/packages/Xamarin.FFImageLoading Main features So what will you find using this library ? I will not explain all the details but the main interesting features of the library. Multi-platform The good po

[Xamarin Forms] Custom bottom bordered entry (iOS & Android)

Image
Custom entry with renderers For my Xamarin Forms project I needed to render an 'Entry' control with a bottom border of a specific color. There are several possibilities but I will show you mine. For that, I used renderers. iOS one is particularly not trivial. The wished result look like that: iOS Renderer [assembly: ExportRenderer(typeof(ExtDatePicker), typeof(ExtDatePickerRenderer))] namespace MyCompany.iOS.Renderers { public class ExtDatePickerRenderer : DatePickerRenderer { protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e) { base.OnElementChanged(e); // Need to connect to Sizechanged event because first render time, Entry has no size (-1). if (e.NewElement != null) e.NewElement.SizeChanged += (obj, args) => { var xamEl = obj as DatePicker; if (xamEl == null) ret

[Xamarin Forms] build error: Unable to cast object of type 'Xamarin.Forms.Xaml.ElementNode' to type 'Xamarin.Forms.Xaml.ValueNode'

Image
Xaml build error For one of my Xamarin project, I just had this build error: This error was related to my XAML code : Unable to cast object of type 'Xamarin.Forms.Xaml.ElementNode' to type 'Xamarin.Forms.Xaml.ValueNode' After searching for a long 'moment', I just didn't understand what happened... My investigation (this process can help you :p) So I decided to remove a large part of my xaml code and then re-add it little by little. Each step I tried to compile to see when error occurs. So In my case, I determined that the piece of code that was going wrong was the following: Ok, it was my mistake but in the code editor, Visual Studio didn't tell me anything. I was trying to bind an event ( I though it was a property ) to a DateTime property... What is not possible. Hope this helps someone to save a few minutes :)

Parse for Xamarin Forms - No PCL, my solution with conditional builds

Image
About Parse In my previous article (or next, we will see ;) I talk about Parse BaaS. This is a 'Back end As Services' that offers you simple but really convenient back end capabilities for storage but also managing users... I approach why I choose this technology for my mobile application, looking for advantages and drawbacks. Parse, after being purchased by Facebook, was closed last year, but fortunately, the source code is open source and Parse still exists . So you can install your own server or use the new Parse on Buddy platform for instance. You can take a look here:  https://buddy.com/parse/ The problem with Parse for Xamarin Forms So, actually the problem is that we can find .NET Xamarin SDK but specifically for iOS and Android frameworks. There is no SDK for Xamarin Forms. The ideal solution could be the following: Many 'pseudo' solutions can be found on internet but I will give you mine, using conditional builds in Visual Studio. I