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

[Enhancement] XAML navigation inside a ListView ItemTemplate uses parent BindingContext instead of that of the ListView item #2232

Closed
louisoftokyo opened this issue Nov 2, 2020 · 1 comment · Fixed by #2404

Comments

@louisoftokyo
Copy link

louisoftokyo commented Nov 2, 2020

Description

When the NavigateTo extension is used in a control inside a ListView ItemTemplate, it uses the parent viewmodel as its BindingContext instead of the ListView item that row is bound to.

Steps to Reproduce

  1. Set up two pages, one of which has a ListView bound to a collection of models (MyModel) with a string "Destination" property set to the name of the other page
  2. In the ListView.ItemTemplate, add a Button with Command = {prism:NavigateTo Name={Binding Destination}
  3. Run the app and click one of the buttons. You'll get an error in the output window showing that the NavigateTo extension is using the ListView page's viewmodel as its BindingContext and therefore failing to find the Destination property, instead of using MyModel as its BindingContext.

Expected Behavior

Navigation to Page2 occurs

Actual Behavior

Navigation to Page2 does not occur, and an exception is thrown:

[0:] Binding: 'Destination' property not found on 'PrismXamlNavigationBugRepro.ViewModels.MainPageViewModel', target property: 'Prism.Navigation.Xaml.NavigateToExtension.Name'
[0:] Warning: NavigateToExtension threw an exception while navigating to ''.
[0:] Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Prism.Navigation.PageNavigationService.NavigateInternal (System.String name, Prism.Navigation.INavigationParameters parameters, System.Nullable`1[T] useModalNavigation, System.Boolean animated) [0x00000] in d:\a\1\s\Source\Xamarin\Prism.Forms\Navigation\PageNavigationService.cs:256

Basic Information

  • Version with issue: 8.0.0.1909
  • Last known good version: N/A
  • Xamarin.Forms version: 4.8.0.1560
  • IDE: Visual Studio 2019

Reproduction Link

https://github.com/louisoftokyo/PrismXamlNavigationBugRepro

@brianlagunas brianlagunas changed the title [Bug] XAML navigation inside a ListView ItemTemplate uses parent BindingContext instead of that of the ListView item [Enhancement] XAML navigation inside a ListView ItemTemplate uses parent BindingContext instead of that of the ListView item Dec 2, 2020
@stale stale bot added the wontfix label Feb 16, 2021
@PrismLibrary PrismLibrary deleted a comment from stale bot Feb 25, 2021
@stale stale bot removed the wontfix label Feb 25, 2021
@dansiegel
Copy link
Member

@louisoftokyo sorry it took so long to get to this one. Thanks for pointing out this bug. The fix will be in the Sponsor Connect feed shortly for you to use :)

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

Successfully merging a pull request may close this issue.

2 participants