wybot
wybot

Reputation: 345

Cath picker selected item = null Xamarin.forms

I want if user won't selection item in picker label's text become this: Error! Not full condition!

I tried something like

        try
        {
            picker.Items[picker.SelectedIndex] = null;
        }

        catch (System.ArgumentNullException)
        {
            Error.IsVisible = true;
            Error.Text = AppResources.ERROR1;
        }

But it doesn't works! Please help me. Thank you!

Upvotes: 0

Views: 570

Answers (1)

Jason
Jason

Reputation: 89082

if SelectedIndex is -1 then no item is selected

if (picker.SelectedIndex < 0) 
{
  Error.IsVisible = true;
  Error.Text = AppResources.ERROR1;
} 

Upvotes: 2

Related Questions