You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
In the ListView.ItemTemplate, add a Button with Command = {prism:NavigateTo Name={Binding Destination}
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
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
@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 :)
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
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
Reproduction Link
https://github.com/louisoftokyo/PrismXamlNavigationBugRepro
The text was updated successfully, but these errors were encountered: