hypnocool
hypnocool

Reputation: 73

Xamarin, What is the difference between tab page click vs button page click?

When i click on the tab page () a new settings page comes on but it's not populated with the info i already entered but it i click on a button (Navigation.PushModalAsync(new SettingsPage());) the page comes on and its populated with info I entered. is there a difference between the two?

//for tab page
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
        xmlns:local="clr-namespace:Bldg"
        x:Class="Bldg.HomePage" >

<local:HistoryLogPage Title="Log"/>
<local:AddDrainsPage Title="Add"/>
<local:SettingsPage Title="Edit Settings"/> 

<Label x:Name="drain1Label" />

</TabbedPage>

//for click button
void NextpageButton_Clicked(object sender, System.EventArgs e)
{ 
Navigation.PushModalAsync(new SettingsPage());
}

//SettingsPage

namespace Bldg
{
public partial class SettingsPage : ContentPage
{

public static string item, username;
public static string location1, location2;
bool is1Empty = string.IsNullOrEmpty(Settings.n1LocationSettings);
bool is2Empty = string.IsNullOrEmpty(Settings.n2LocationSettings);

List<string> list;

public SettingsPage()
{

InitializeComponent();
drainquantity();

list = new List<string>();
    list.Add("1");
    list.Add("2");

locationPicker1.SelectedIndexChanged += drain1Handle_SelectedIndexChanged;
locationPicker2.SelectedIndexChanged += drain2Handle_SelectedIndexChanged;

//nameofpickerinxamlfile.On<iOS().SetUpdateMode(UpdateMode.WhenFinished);


locationPicker1.On<iOS>().SetUpdateMode(UpdateMode.WhenFinished);
locationPicker2.On<iOS>().SetUpdateMode(UpdateMode.WhenFinished);

drainxPicker.SelectedItem = Settings.DrainquantitySettings;
locationPicker1.SelectedItem = Settings.n1LocationSettings;
locationPicker2.SelectedItem = Settings.n2LocationSettings;

nameEntry.Text = Settings.NameSettings;

clearButton.IsVisible = false;

drainlocationPicker2.IsEnabled = false;

drainxPicker.SelectedItem = Settings.DrainquantitySettings;
}

//this is fired when user changes or selects new selection
void drainxHandle_SelectedIndexChanged(object sender, System.EventArgs e)
{
//to get the value of user selected going to be use in switch; then save in a 
variable
var drainx = drainxPicker.Items[drainxPicker.SelectedIndex];

item = (string)drainxPicker.SelectedItem;


bool isdrainxEmpty = string.IsNullOrEmpty(Settings.DrainquantitySettings);

if (isdrainxEmpty == true)
{

//switch for user selected in drainpicker

switch (drainx)
{               
case "1":
n1Gridrow.IsVisible = true;
locationPicker1.IsVisible = true;
n2Gridrow.IsVisible = false;

if (is1Empty == true)
{
drainxPicker.IsEnabled = true;
}
else
drainxPicker.IsEnabled = false;

break;

case "2":
n1Gridrow.IsVisible = true;
n2Gridrow.IsVisible = true;
locationPicker2.IsEnabled = false;

break;

}  //switch end
}
else
{
drainxPicker.IsEnabled = false;
nameEntry.IsEnabled = false;
n1Gridrow.IsVisible = true;
n2Gridrow.IsVisible = true;

locationPicker1.IsEnabled = false;
locationPicker2.IsEnabled = false;

settingsaveButton.IsVisible = false;

}

}

void n1Handle_SelectedIndexChanged(object sender, System.EventArgs e)
{

location1 = (string)locationPicker1.SelectedItem;
if (is1Empty == true)
{
locationPicker2.IsEnabled = true;
n2Label.IsVisible = true;

locationPicker2.Items.Remove((string)locationPicker1.SelectedItem);
}

drainxPicker.IsEnabled = false;
locationPicker1.IsEnabled = false;

}

void n2Handle_SelectedIndexChanged(object sender, System.EventArgs e)
{
location2 = (string)locationPicker2.SelectedItem;

if (is2Empty == true)
{
locationPicker2.IsEnabled = true;
}
drainxPicker.IsEnabled = false;
locationPicker2.IsEnabled = false;

}

void nxy1()
{
foreach (var location in list)
{
locationPicker1.Items.Add(location);
}

}


void nxy2()
{

foreach (var location in list)        
{
locationPicker2.Items.Add(location);
} 
}

void settingsaveButton_Clicked(object sender, System.EventArgs e)
{
bool isNameEmpty = string.IsNullOrEmpty(nameEntry.Text);

if (isNameEmpty == true)
{
DisplayAlert("Enter Name", "PLEASE", "OK");
}

else
{

Navigation.PushModalAsync(new HomePage());



//saving to Settings
Settings.n1LocationSettings = location1;
Settings.n2LocationSettings = location2;
Settings.NameSettings = username;
Settings.DrainquantitySettings = item;

drainxPicker.IsEnabled = false;
}

}

void entryNameHandle_Unfocused(object sender, Xamarin.Forms.FocusEventArgs e)
{
username = nameEntry.Text;
}

void clearHandle_Clicked(object sender, System.EventArgs e)
{   
Settings.ClearAllData();
}
}
}

I expect that when i click on tabbed settings page, i go to the settings page with info entered populated. just like the button click it goes to settings page already populated with user entered.

Upvotes: 0

Views: 123

Answers (1)

nevermore
nevermore

Reputation: 15796

Generally, tabbed settings page and pushed settings page is the same. They are all new fresh settings page.

From your code, we can see that you are setting the value of Picker by Settings plugin:

drainxPicker.SelectedItem = Settings.DrainquantitySettings;
locationPicker1.SelectedItem = Settings.n1LocationSettings;
locationPicker2.SelectedItem = Settings.n2LocationSettings;

So, whether the info entered will be populated or not when you go to the setting page is depending on the values in Settings.

For example:

If Settings.DrainquantitySettings; has value, then drainxPicker's info will be populated.

Check the Values in your Setting when you go to tabbed settings page and pushed settings page to find any difference.

Upvotes: 1

Related Questions