Issue
I have
Page1.xaml
<Label x:Name="getPreferences" /> <Button x:Name="one" Clicked="one_Clicked"/>
Page1.xaml.cs
public Page1() { string getpre = Preferences.Get("PreOne", "defaultpre"); getPreferences.Text = getpre; } private async void one_Clicked(object sender, EventArgs e) { PopupNavigation.Instance.PushAsync(new Popup()); }
Popup.xaml (using Rg Popup)
<popup:PopupPage .... <StackLayout x:Name="ss"> <Image Source="img"/> <Label Text="Testtttt" /> <StackLayout.GestureRecognizers> <TapGestureRecognizer Tapped="ss_Tapped" /> </StackLayout.GestureRecognizers> </StackLayout> </popup:PopupPage>
Popup.xaml.cs
private void ss_Tapped(object sender, EventArgs e) { string setone = "01"; Preferences.Set("PreOne", setone); }
How can I get the value of Preferences
to assign to the Label getPreferences
without me having to reload the page Page1. Please help. Thank you
Solution
Preferences Essential package have no event for changing preferences , so you have to get your value every time you change it . i suggest you to create your own event in popup and fire it when your value changed
1.PopUp.xaml.cs
public event EventHandler PreOneChanged;
private void ss_Tapped(object sender, EventArgs e)
{
string setone = "01";
Preferences.Set("PreOne", setone);
PreOneChanged?.Invoke(setone,EventArgs.Empty);
}
2.Page1.xaml.cs
public Page1()
{
Init();
}
private void Init()
{
string getpre = Preferences.Get("PreOne", "defaultpre");
getPreferences.Text = getpre;
}
private async void one_Clicked(object sender, EventArgs e)
{
var popUp = new Popup();
popUp.PreOneChanged += (ss, ee) =>
{
Init();
};
PopupNavigation.Instance.PushAsync(popUp);
}
Now when your value changed in PopUp your event call and in page will change that
Answered By - Amir Hossein Khademi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.