Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command bindings are not re-established when navigating back and forth in UIInterface samples #484

Open
TheKoren opened this issue Jun 14, 2024 · 4 comments

Comments

@TheKoren
Copy link

Due to how the navigation stack is being managed the command bindings are not properly refreshed when navigating between views in UserInterface samples.

Expected Behavior

Navigation is possible between different Views without reloading the application.

Possible Solution

I've tried an approach where i reset the 'BindingContext' in the 'OnAppearing' method and it solves the problem.

Steps to Reproduce

  1. Open 'UserInterface\Layouts\StackLayoutDemos' solution.
  2. Run the application.
  3. Select the AlignmentPage demo.
  4. Navigate back to the MainPage using the back button.
  5. Try to select any of the demos available from MainPage UI. Nothing should happen in it's current form.

Possible Implementation

Adding this to the MainPage solves the problem.

protected override void OnAppearing()
{
    base.OnAppearing();
    BindingContext = null;
    BindingContext = this;
}
@jfversluis
Copy link
Member

I don't think I fully understand the problem, but looking at the solution I highly doubt that this is something we should want to be honest. Doesn't really seem to be a great practice. Refreshing the whole BindingContext will reevaluate all the bindings on a page and doing so during the appearing event might cause sluggish, hanging user interfaces.

Could you maybe elaborate a bit more on what the problem is that you're seeing? Also is this happening on one platform or all the platforms?

@gcadmes-extron
Copy link

gcadmes-extron commented Jul 3, 2024

@jfversluis Navigation only works once. This sample for example, once you click on any of the navigable items in the TableView, navigating back to the MainPage, the navigable items are no longer navigable.
Coincidently, this also happens on any other sample that use the same navigation implementation.

Using the latest VS, download your sample as a .zip file and this should be easily reproducible.

Fwiw, clicking the first item in the TableView "Draw Shapes" actually crashes the app.

@TheKoren
Copy link
Author

TheKoren commented Jul 7, 2024

For some reason I haven't got the notifications for this thread, but the issue is exactly what @gcadmes-extron wrote above.

If refreshing the BindingContext is not optimal, we could just change the implementation of the navigation command. I've used a different solution for it in my own projects, and they work just fine.

Current version:

NavigateCommand = new Command<Type>(
				async (Type pageType) =>
				{
					Page page = (Page)Activator.CreateInstance(pageType);
					await Navigation.PushAsync(page);
				});

@nazar322

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants