Posts

Showing posts from May, 2018

Read Contacts Data on iOS and Android in xamarin forms

Image
Step 1 :  Add the following plugin in your projects : https://www.nuget.org/packages/Xamarin.Forms.Contacts/ PERMISSIONS :     1- android :   < uses-permission android : name = " android.permission.READ_CONTACTS " /> 2- IOS : < key >NSContactsUsageDescription</ key > < string >We need contact permission to do ...</ string > Usage : you can read contacts in portable project : var contacts = await Plugin.ContactService.CrossContactService.Current.GetContactListAsync(); Example : Page code : using System ; using System . Collections . Generic ; using System . Linq ; using System . Text ; using System . Threading . Tasks ; using Xamarin . Forms ; namespace Sample . ContactService { public partial class MainPage : ContentPage { # pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is co

knob control in xamarin forms

Image
you can create knob control by following steps Step 1 :  Add the following class in portable project :     public class Knob : View     {         public static readonly BindableProperty MinProperty = BindableProperty.Create<Knob,float> (p => p.Min, 0);         public static readonly BindableProperty MaxProperty = BindableProperty.Create<Knob,float> (p => p.Max, 100);         public static readonly BindableProperty CurrentProperty = BindableProperty.Create<Knob,float> (p => p.Current, 50);         public static readonly BindableProperty BoundsProperty = BindableProperty.Create<Knob,Rectangle> (p => p.Bounds, new Rectangle(0,0,300,300));         public static readonly BindableProperty ShowTouchPathProperty = BindableProperty.Create<Knob,bool> (p => p.ShowTouchPath, false);         public float Min {             get { return (float) GetValue(MinProperty); }             set { SetValue (MinProperty, value)

Messaging Center in Xamarin Forms

Xamarin.Forms has a built-in messaging mechanism to promote decoupled code.  This way, view models and other components do not need to know each other. They can communicate by a simple messaging contract. There a basically two main ingredients for using the MessagingCenter. Subscribe; listen for messages with a certain signature (the contract)  and execute code when a message is received. A message can have multiple subscribers. Send; sending a message for subscribers to act upon.  example :  Here we will see a simple example of using the MessagingCenter in Xamarin.Forms.  First, let's have a look at subscribing to a message.  In the TestMessaging model we subscribe to a message coming from the MainPage.  The message should be "Hi" and when we receive it, we register a handler  which sets the property Greeting. Lastly this means the current TestMessaging  instance is registering for this message.       public TestMessaging() {         MessagingCent

Geolocator in Xamarin Forms

Step 1: Add the following plugin in your project : https://www.nuget.org/packages/Xam.Plugin.Geolocator/ you can find plugin  Documentation at : https://jamesmontemagno.github.io/GeolocatorPlugin/ Step 2 : add the following xaml in your page :  <StackLayout Spacing="10" Padding="10">     <Button x:Name="buttonGetGPS" Text="Get GPS"/>      <Label x:Name="labelGPS"/>     <Button x:Name="buttonTrack" Text="Track Movements"/>     <Label x:Name="labelGPSTrack"/>      <Label Text=""/>         </StackLayout> Step 3 : Use the following code in C# file : namespace PluginDemo {     public partial class GeolocatorPage : ContentPage     {         public GeolocatorPage()         {             InitializeComponent(); buttonGetGPS.Clicked += async (sender, args) =>             {             try             {                 var

Nightly Builds In Xamarin Forms

Image
 to try the latest-and-greatest in Xamarin.Forms through our new nightly build feed. Nightly builds will enable a tighter feedback loop with those of you in our community as we strive for quality and performance improvements. It also allows you to test and review changes and features that will appear in the next pre-release. How to Access Nightly Builds Our nightly builds are distributed via a custom NuGet feed. To access these builds, configure a new source in either the Visual Studio or Xamarin Studio NuGet Package Manager, select that source when browsing packages, and be sure to check the pre-release option. You can find the feed at Xamarin.Forms Nightly: https://www.myget.org/F/xamarinforms-ci/api/v2 Visual Studio :  Open the settings panel by going to Tools > NuGet Package Manager > Package Manager Settings. Select the Package Sources page. Click the green plus icon to add a new source. Enter the name and source with the information above. Click Update and

Custom BoxView In xamarin forms

Step 1 :  Add the following class in PCL project :     public class ExtendedBoxView : BoxView     {        /// <summary>        /// Respresents the background color of the button.        /// </summary>        public static readonly BindableProperty BorderRadiusProperty = BindableProperty.Create<ExtendedBoxView, double>(p => p.BorderRadius, 0);         public double BorderRadius { get { return (double)GetValue(BorderRadiusProperty); } set { SetValue(BorderRadiusProperty, value); } }         public static readonly BindableProperty StrokeProperty = BindableProperty.Create<ExtendedBoxView, Color>(p => p.Stroke, Color.Transparent);         public Color Stroke { get { return (Color)GetValue(StrokeProperty); } set { SetValue(StrokeProperty, value); } }         public static readonly BindableProperty StrokeThicknessProperty = BindableProperty.Create<ExtendedBoxView, double>(p => p.StrokeThickness, 0);         public double StrokeThickness { get

Zoom an Image with the Pinch gesture in xamarin forms

Step 1 : add xaml code in your page : <Image Source="test.jpg">  <Image.GestureRecognizers>   <PinchGestureRecognizer PinchUpdated="OnPinchUpdated" />  </Image.GestureRecognizers> </Image> Step 2 : add this code in your code file :         private double startScale;         private double currentScale;         private double xOffset;         private double yOffset;         void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)         {             if (e.Status == GestureStatus.Started)             {                 startScale = Content.Scale;                 Content.AnchorX = 0;                 Content.AnchorY = 0;             }             if (e.Status == GestureStatus.Running)             {                 currentScale += (e.Scale - 1) * startScale;                 currentScale = Math.Max(1, currentScale);                 double renderedX = Content.X + xOffset;                 double delt

Encrypt and Decrypt in c#

Step 1 :  using the following assembly using System.Security.Cryptography; Step 2 : add Encrypt & Decrypt mehtod to your class public string Encrypt(string clearText, string Password)         {             byte[] clearData = Encoding.Unicode.GetBytes(clearText);             PasswordDeriveBytes bytes = new PasswordDeriveBytes(Password, new byte[] { 50, 21, 32, 119, 19, 4, 56, 76, 23, 65, 58, 23, 43 });             return Convert.ToBase64String(this.Encrypt(clearData, bytes.GetBytes(0x20), bytes.GetBytes(0x10)));         } public string Decrypt(string cipherText, string Password)         {             byte[] cipherData = Convert.FromBase64String(cipherText);             PasswordDeriveBytes bytes = new PasswordDeriveBytes(Password, new byte[] { 50, 21, 32, 119, 19, 4, 56, 76, 23, 65, 58, 23, 43 });             byte[] buffer2 = this.Decrypt(cipherData, bytes.GetBytes(0x20), bytes.GetBytes(0x10));             return Encoding.Unicode.GetString(buffer2); Step 3

How to Sorting Genric List By Their Properties in c#

** To sort generic lists ,The following steps are required for sorting the list: Step1 :  Create class for sorting and implement interface IComparable<Type> wheres Type will reflect class for comparison Ex:  public class Racer : IComparable<Racer> Step 2 :  Add properties in the above class : Ex:         public string FirstName { get; set; }         public string LastName { get; set; }         public string Country { get; set; }         public int Wins { get; set; } Step 3 :  You have to override method of IComparable but it won't be executed for sorting : Ex:  public int CompareTo(Racer other) Step 4 : Create a class for doing comparison which will implement IComparer for doing comparison Ex: public class RacerComparer : IComparer<Racer> Step 5 :  Add enum to save what will be items through sorting will be done. Ex: public enum CompareType Step 6 :   Override compare function o