Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Why i can't use this on switch case? Please help

$
0
0

Basically, i have a MasterDetailPage where i have a few items with a listview (programmaly). And... on every entrys i have a TextChanged where use a variable which is type bool called "certeza". The purpose of all of that is for asking to the user if he/she wants to leave without saving it. So i did this:

private async void View_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
Item itens = e.SelectedItem as Item;
switch (itens.Text)
{
case "Abastecimento":
if (App.certeza == true)
{
var response1 = await DisplayAlert("Leaving", "Do you want to leave without saving?", "Yes", "No");
if (response1)
{
Detail = new NavigationPage(new Abastecimento());
App.certeza = false;
}
}
else
Detail = new NavigationPage(new Abastecimento());
brake;
}

With these code, if i press "No" on DisplayAlert, i cannot open that page anymore if i don't open another one. The problem is that "break". What i tried to do was:

      switch (itens.Text)
      {
          case "Abastecimento":
              if (App.certeza == true)
              {
                  var response1 = await DisplayAlert("Leaving", "Do you want to leave without saving?", "Yes", "No");
                  if (response1)
                  {
                      Detail = new NavigationPage(new Abastecimento());
                      App.certeza = false;
                      break;
                  }
              }
              else
              {
                  Detail = new NavigationPage(new Abastecimento());
                  brake;
              }

(What i want to do is: ) If i press "No", the switch does not break and when i want to press the page i previously selected, the page will be available and ready to open.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>