using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace App2
{
public partial class MainPage : ContentPage
{
bool dateselected = false;
public MainPage()
{
InitializeComponent();
dPicker.DateSelected += DPicker_DateSelected;
dPicker.MaximumDate = DateTime.Now;
dPicker.Unfocused += DPicker_Unfocused;
btnclear.Clicked += Btnclear_Clicked;
}
private void DPicker_DateSelected(object sender, DateChangedEventArgs e)
{
dateselected = true;
lblDate.Text = dPicker.Date.ToString();
}
private void DPicker_Unfocused(object sender, FocusEventArgs e)
{
if (dateselected == true)
{
lblDate.Text = dPicker.Date.ToString();
}
else
{
lblDate.Text = DateTime.Now.ToString();
}
}
private void Btnclear_Clicked(object sender, EventArgs e)
{
lblDate.Text = "- - - - -";
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace App2
{
public partial class MainPage : ContentPage
{
bool dateselected = false;
public MainPage()
{
InitializeComponent();
dPicker.DateSelected += DPicker_DateSelected;
dPicker.MaximumDate = DateTime.Now;
dPicker.Unfocused += DPicker_Unfocused;
btnclear.Clicked += Btnclear_Clicked;
}
private void DPicker_DateSelected(object sender, DateChangedEventArgs e)
{
dateselected = true;
lblDate.Text = dPicker.Date.ToString();
}
private void DPicker_Unfocused(object sender, FocusEventArgs e)
{
if (dateselected == true)
{
lblDate.Text = dPicker.Date.ToString();
}
else
{
lblDate.Text = DateTime.Now.ToString();
}
}
private void Btnclear_Clicked(object sender, EventArgs e)
{
lblDate.Text = "- - - - -";
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App2"
x:Class="App2.MainPage">
<ContentPage.Content>
<StackLayout>
<DatePicker x:Name="dPicker" VerticalOptions="Center" HorizontalOptions="Center"/>
<Label x:Name="lblDate" FontSize="20" Text="- - - - -" VerticalOptions="Center" HorizontalOptions="Center"/>
<Button x:Name="btnclear" Text="Clear" VerticalOptions="Center" HorizontalOptions="Center"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
No comments:
Post a Comment