Sunday, 13 January 2019

Selecting A Date From Calendar Using Xamarin.Forms

XAML Code

  1. <?xml version="1.0" encoding="utf-8" ?>  
  2. <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:DatePicker" x:Class="DatePicker.MainPage">  
  3.     <StackLayout HorizontalOptions="Center" VerticalOptions="Center">  
  4.         <DatePicker x:Name="MainDatePicker" MinimumDate="1/1/2018" MaximumDate="12/31/2020" DateSelected="MainDatePicker_DateSelected" />  
  5.         <Label x:Name="MainLabel" FontSize="20" TextColor="Blue" /> </StackLayout>  
  6. </ContentPage>  
In this, we use DatePicker for displaying the calendar. For that calendar, let us set the minimum and maximum ranges of that calendar. Then, use an event for displaying the date on the label.


 


 
Now, open MainPage.xaml.cs file for writing the code.

C# Code
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using Xamarin.Forms;  
  7. namespace DatePicker {  
  8.     public partial class MainPage: ContentPage {  
  9.         public MainPage() {  
  10.             InitializeComponent();  
  11.         }  
  12.         private void MainDatePicker_DateSelected(object sender, DateChangedEventArgs e) {  
  13.             MainLabel.Text = e.NewDate.ToLongDateString();  
  14.         }  
  15.     }  
  16. }  




No comments:

Post a Comment

All About .NET MAUI

  What’s .NET MAUI? .NET MAUI (.NET Multi-platform App UI) is a framework for building modern, multi-platform, natively compiled iOS, Androi...

Ads2