Posts

Showing posts with the label XAMARIN

[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] Entry with rounded borders in your app

Image
Entry with rounded borders in your app (Xamarin Forms, NET MAUI) I know for some people it will be obvious, but I always seepeople asking how to make a custom Entry control with rounded borders...  To add rounded corners globally to Entry controls in a Xamarin Forms or .NET MAUI application, you can define a Style in the App.xaml (or Styles.xaml for .NET MAUI). This style will automatically apply to all Entry controls in your app, saving you from having to manually style each one. Example Define the global style in App.xaml : <Application.Resources> <ResourceDictionary> <Style TargetType="Entry"> <Setter Property="BackgroundColor" Value="White"/> <Setter Property="TextColor" Value="Black"/> <Setter Property="CornerRadius" Value="10"/> <Setter Property="HeightRequest" Value="50"/>

[Xamarin Forms]Page navigation summary

Image
[Xamarin Forms] Page navigation summary 1- The different navigation possibilities In this article will we list and sum up how we can navigate inside a Xamarin Forms application.  In Xamarin.Forms, you can navigate between pages using several methods, we will enumerate it and give a brief description / use case for each : Push/Pop Navigation : Using Navigation.PushAsync() and Navigation.PopAsync() for stack-based navigation. Modal Navigation : Using Navigation.PushModalAsync() and Navigation.PopModalAsync() for displaying pages modally. Master-Detail Navigation : Using MasterDetailPage to manage a master menu and a detail page. Tabbed Navigation : Using TabbedPage for navigation between different tabs. Carousel Navigation : Using CarouselPage to swipe through pages in a carousel-style interface. Shell Navigation : Using Xamarin.Forms Shell for a unified navigation paradigm with URL-based routing and flyout menus. Custom Navigation : Or if you want to customize and design a good

[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

Understanding .NET Standard

Image
If as me, you don't really understand all subtleties between .NET Core and .NET Standard , I suggest you to have a look at the following article. It explains some history about .NET Framework and how .NET Standard is born. >>  Xamarin blog: A brief history of .NET Standard Which version to use ? For me, an important point to master for my own projects, is to know which platforms I can reach with a specific .NET Standard or .NET Core library. The following table illustrate the compatibility between each .NET implementation: For instance, - if you build a Xamarin Android v. 7.0 application, you could use versions 1.0 up to 1.6 .NET Standard librairies into your project - or if you have a .NET Standard v. 1.4 library, you could only build Android  v. 7.0  applications ( not v. 8.0) Intersting References about .NET Standard: Xamarin blog: A brief history of .NET Standard .NET Standard official website .NET Standard, table version video

Full Xamarin Documentation available on Microsoft.com

Image
New 'Xamarin' menu available If you are a Xamarin developer, you will be happy to know that the "full" Xamarin Platform's documentation is now available on microsoft.com website.  This website looks really clear , so it should be easy to find what you need... Microsoft documentation portal:   https://docs.microsoft.com If you select the "Xamarin" menu, you will be redirected to the following page: This is the entry point to many chapters describing the platform like: - technical / language documentation - UI (with XAML) documentation but you will also find: - deployement tutorials - mobile continuous delivery tutorials - data / database articles - code samples - and so much more ! So let's go coding Xamarin !

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

Visual Studio for MAC, review (fr)

Image
If you are a developer, there are many chance that you already used Visual Studio, the famous Microsoft's IDE. Visual Studio for MAC is borned a few weeks ago . But is it a productive tool like on PC ? If you are a Xamarin Developer and never tried it, I suggest you to take a look at this short review to get some clues ! This review is avaible in french on mobilissime.fr : http://www.mobilissime.fr/index.php/2017/06/20/visual-studio-pour-mac-petite-revue-de-lide/

[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