Hello,
Do you want to transfer data when EmotesPage
page navigate back to the Profile
page?
If so, you can do this by using event call back.
Firstly, we can create a CustomEventArgs for event call back.
public class CustomEventArgs : EventArgs
{
private readonly string customString;
public CustomEventArgs(string customString)
{
this.customString = customString;
}
public string CustomString
{
get { return this.customString; }
}
}
Then open your EmotesPage page, add call back event, for example, when execute EmotesView_SelectionChanged_1
, you want to transfer image's source to the Profile
page like following EmotesView_SelectionChanged_1
, you can use Navigation.PopAsync();
to navigate back page.
And send data to the Profile
page by NaviBackEvent?.Invoke(this, new CustomEventArgs(EmoteSelected.Image));
.
public partial class EmotesPage : ContentPage
{
public event EventHandler<CustomEventArgs> NaviBackEvent;
private void OnNaviBackEvent(string image)
{
if (NaviBackEvent != null)
{
NaviBackEvent(this, new CustomEventArgs(image));
}
}
private async void EmotesView_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
var EmoteSelected = e.CurrentSelection[0] as EmotesModel;
Profile EmoteClicked = new Profile(EmoteSelected);
await Navigation.PopAsync();
NaviBackEvent?.Invoke(this, new CustomEventArgs(EmoteSelected.Image));
}
Next, open your Profile
page, I make a test in the Emote1 button click event, when navigate back, change the select image for imagebutton like following code.
public void ImageButton_Clicked_1(object sender, EventArgs e)
{
ImageButton imageButton= sender as ImageButton;
EmotesPage emotesPage = new EmotesPage();
emotesPage.NaviBackEvent +=(NaviSender,CustomEventArgs)=>{
Emote1.Source = CustomEventArgs.CustomString;
};
Navigation.PushAsync(emotesPage);
}
Please note, if you use Navigation.PushAsync
, you have to wrap the NavigationPage
in the App.xaml.cs
.
public App()
{
InitializeComponent();
MainPage =new NavigationPage( new EmotesPage());
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.