Posts

Showing posts with the label Xamarin.Forms

Xamarin Forms toaster notification for android and iOS

A simple solution is by using the Dependency Service you can easily get the Toast notification in both Android and iOS.   Create an interface in your Xamarin forms package. public interface IMessage { void LongAlert ( string message ) ; void ShortAlert ( string message ) ; }   Android Project   [ assembly: Xamarin.Forms.Dependency(typeof(MessageAndroid)) ] namespace Your.Namespace { public class MessageAndroid : IMessage { public void LongAlert ( string message ) { Toast.MakeText(Application.Context, message, ToastLength.Long).Show(); } public void ShortAlert ( string message ) { Toast.MakeText(Application.Context, message, ToastLength.Short).Show(); } } }    iOS Project   [ assembly: Xamarin.Forms.Dependency(typeof(MessageIOS)) ] namespace Your.Namespace { public class MessageIOS : IMessage { const double LONG_DELAY = 3.5 ; const double SH

Remove icon from action bar for xamarin forms android project

Put the below code in xamarin.android (xamarin.droid) project. [assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomNavigationRenderer))] namespace Example {     public class RootNavigationRenderer : NavigationRenderer     {         protected override void OnElementChanged(ElementChangedEventArgs e)         {             base.OnElementChanged(e);             RemoveAppIconFromActionBar();         }         void RemoveAppIconFromActionBar()         {             var actionBar = ((Activity)Context).ActionBar;             actionBar.SetIcon(new ColorDrawable(Color.Transparent.ToAndroid()));         }     } }

Gesture Recognizers with Xamarin.Forms

Why gestures ?   Some controls does not have support click event. In order to achieve add the below code this will enabling click event in the controls.. Gestures are mainly of 3 types Tap Gesture Recognizer Pinch Gesture Recognizer Pan Gesture Recognizer 1) Tap Gesture Recognizer var tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += tapGestureRecognizer_Tapped; Controler_Name.GestureRecognizers.Add(tapGestureRecognizer); void tapGestureRecognizer_Tapped(object sender, EventArgs e) { ........//Code here } 2) Pinch Gesture Recognizer var pinchGestureRecognizer = new PinchGestureRecognizer(); pinchGestureRecognizer.PinchUpdated += pinchGestureRecognizer_PinchUpdated; Controler_Name.GestureRecognizers.Add(pinchGestureRecognizer); void pinchGestureRecognizer_PinchUpdated(object sender, PinchGestureUpdatedEventArgs e) { ........//Code here } 3) Pan Gesture Recognizer var panG