How to disable button until all entries filled ? Help! (in following code button is not enabling)

FarhanFarriFarhanFarri USMember ✭✭
edited October 2 in Xamarin.Forms

Xaml Code

<Label Text="Full Name"/>
    <Entry x:Name="EntFullName" Placeholder="Enter Full Name"/>

    <Label Text="Cell Number"/>
    <Entry x:Name="EntCellNumber" Keyboard="Telephone" Placeholder="Enter Cell Number"/>

    <Label Text="City"/>
    <Picker x:Name="PkrAddRequestCity" SelectedItem="None" Title="Choose City">
        <Picker.Items>
            <x:String>None</x:String>
            <x:String>Lahore</x:String>
        </Picker.Items>
    </Picker>

    <Label Text="Hospital"/>
    <Picker x:Name="PkrAddRequestHospital" Title="Choose Hospital">
        <Picker.Items>
            <x:String>None</x:String>
            <x:String>Bajwa Hospital, Shahdara Town</x:String>
            <x:String>Bajwa Hospital, Iqbal Town</x:String>
            <x:String>Doctors Hospital</x:String>
            <x:String>Fatima Memorial Hospital</x:String>
            <x:String>Gulab Devi Chest Hospital</x:String>
            <x:String>Hameed Latif Hospital</x:String>
            <x:String>Ittefaq Hospital</x:String>
            <x:String>Janki Devi Hospital</x:String>
            <x:String>Jinnah Hospital</x:String>
            <x:String>Lady Aitchison Hospital</x:String>
            <x:String>Lady Willingdon Hospital</x:String>
            <x:String>Lahore General Hospital</x:String>
            <x:String>Mayo Hospital</x:String>
            <x:String>National Hospital</x:String>
            <x:String>Nawaz Sharif Social Security Hospital, Multan Road</x:String>
            <x:String>Omar Hospital and Carddiac Center (Jail Road)</x:String>
            <x:String>Punjab Institute of Cardiology</x:String>
            <x:String>Punjab Institute of Mental Health</x:String>
            <x:String>Punjab Social Security Hospital</x:String>
            <x:String>Railway Karen Hospital</x:String>
            <x:String>Services Hospital</x:String>
            <x:String>Shaikh Zayed Hospital</x:String>
            <x:String>Shalamar Hospital (Shalamar Institute of Health Sciences)</x:String>
            <x:String>Shaukat Khanum Memorial Cancer Hospital and Research Centre</x:String>
            <x:String>Sir Ganga Ram Hospital</x:String>
            <x:String>The Children's Hospital</x:String>
            <x:String>University Dental Hospital - University of Lahore</x:String>
            <x:String>University Teaching Hospital - University of Lahore</x:String>
            <x:String>Wapda Hospital</x:String>
        </Picker.Items>
    </Picker>

    <Label Text="Blood Group"/>
    <Picker x:Name="PkrAddRequestBloodGroup" Title="Your Blood Group">
        <Picker.Items>
            <x:String>None</x:String>
            <x:String>A+</x:String>
            <x:String>A-</x:String>
            <x:String>B+</x:String>
            <x:String>B-</x:String>
            <x:String>AB+</x:String>
            <x:String>AB-</x:String>
            <x:String>O+</x:String>
            <x:String>O-</x:String>
        </Picker.Items>
    </Picker>

    <Button Text="Add" x:Name="BtnAddRequest" BackgroundColor="Brown" IsEnabled="False"/>

======================================
Xaml.cs

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
        GetValues();
    }

    private void GetValues()
    {
        if (string.IsNullOrEmpty(EntFullName.Text) == false && string.IsNullOrEmpty(EntCellNumber.Text) == false &&
            string.IsNullOrEmpty(PkrAddRequestCity.Items[PkrAddRequestCity.SelectedIndex]) == false &&
            string.IsNullOrEmpty(PkrAddRequestBloodGroup.Items[PkrAddRequestBloodGroup.SelectedIndex]) == false &&
            string.IsNullOrEmpty(PkrAddRequestHospital.Items[PkrAddRequestHospital.SelectedIndex]) == false)
        {
            BtnAddRequest.IsEnabled = true;
        }
        else
        {
            BtnAddRequest.IsEnabled = false;

        }
    }
}

Answers

Sign In or Register to comment.