How to Make Lock Screen in Xamarin Crossplatform






First Create xaml page of folleowing coding

-----------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp.MainCPage3">

    <StackLayout VerticalOptions="Center" HorizontalOptions="Center">
        <Entry x:Name="displayLabel" TextColor="White"  PropertyChanged="displayLabel_PropertyChanged" FontSize="42" IsPassword="True" VerticalOptions="Center" HorizontalTextAlignment="Center"  BackgroundColor="Transparent"  />
        <Button x:Name="backspaceButton" Text="&#8666;" TextColor="White" Font="52" IsEnabled="False" Clicked="backspaceButton_Clicked"  BackgroundColor="Transparent" />
        <StackLayout Orientation="Horizontal">
            <Button Text="7" TextColor="White"  Font="32"  StyleId="7"  Clicked="OnDigitButtonClicked" BackgroundColor="Transparent"/>
            <Button Text="8" TextColor="White" StyleId="8" Font="32" Clicked="OnDigitButtonClicked"  BackgroundColor="Transparent" />
            <Button Text="9" TextColor="White" StyleId="9" Font="32" Clicked="OnDigitButtonClicked"  BackgroundColor="Transparent" />
        </StackLayout>
      
        <StackLayout Orientation="Horizontal">
            <Button Text="4" TextColor="White" StyleId="4" Font="32"  Clicked="OnDigitButtonClicked"  BackgroundColor="Transparent" />
            <Button Text="5" TextColor="White" StyleId="5" Font="32" Clicked="OnDigitButtonClicked"  BackgroundColor="Transparent" />
            <Button Text="6" TextColor="White" StyleId="6" Font="32" Clicked="OnDigitButtonClicked"  BackgroundColor="Transparent" />
        </StackLayout>
        <StackLayout Orientation="Horizontal">
            <Button Text="1" TextColor="White" StyleId="1" Font="32" Clicked="OnDigitButtonClicked"  BackgroundColor="Transparent" />
            <Button Text="2" TextColor="White" StyleId="2" Font="32" Clicked="OnDigitButtonClicked"  BackgroundColor="Transparent" />
            <Button Text="3" TextColor="White"  StyleId="3" Font="32" Clicked="OnDigitButtonClicked"  BackgroundColor="Transparent" />
        </StackLayout>
        <Button Text="0" TextColor="White" StyleId="0" Font="32" Clicked="OnDigitButtonClicked"  BackgroundColor="Transparent" />
    </StackLayout>
-----------------------------------------------------------------------------


Make Xaml.cs file by following coding



-----------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace MyApp
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MainCPage3 : ContentPage
    {
        App app = Application.Current as App;
        public MainCPage3()
        {
            this.BackgroundImage = "a.jpg";
            BindingContext = this;

            InitializeComponent();

            displayLabel.Text = displayLabel.Text;
            backspaceButton.IsEnabled = displayLabel.Text != null && displayLabel.Text.Length > 0;

           
        }

        private void backspaceButton_Clicked(object sender, EventArgs e)
        {
            string text = displayLabel.Text;
            displayLabel.Text = text.Substring(0, text.Length - 1);
            backspaceButton.IsEnabled = displayLabel.Text.Length > 0;
            displayLabel.Text = displayLabel.Text;
           // Navigation.PushAsync(new LoginPage());
        }

        void OnDigitButtonClicked(object sender, EventArgs args)
        {
            Button button = (Button)sender;
            displayLabel.Text += (string)button.StyleId;
            backspaceButton.IsEnabled = true;
            displayLabel.Text = displayLabel.Text; }

        private void displayLabel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (displayLabel.Text == ("0000"))
            {
                Navigation.PushAsync(new LoginPage());
            }
            else
            {
                backspaceButton.IsEnabled = displayLabel.Text != null && displayLabel.Text.Length > 0;
            }
        }
    }
}
----------------------------------------------------------------------------------------------------


Comments

Popular posts from this blog