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

[Bug] Cannot navigate via EventToCommandBehavior in XAML #2484

Closed
Nate129 opened this issue Jun 15, 2021 · 3 comments
Closed

[Bug] Cannot navigate via EventToCommandBehavior in XAML #2484

Nate129 opened this issue Jun 15, 2021 · 3 comments

Comments

@Nate129
Copy link

Nate129 commented Jun 15, 2021

Description

When attempting to navigate via XAML and EventToCommandBehavior like so:

<ListView.Behaviors>
      <prism:EventToCommandBehavior EventName="ItemTapped"
                                    Command="{prism:NavigateTo 'DetailPage'}"
                                    EventArgsParameterPath="Item" />
</ListView.Behaviors>

The following exception is thrown:

System.ArgumentNullException: 'Value cannot be null.
Parameter name: TargetElement'

Steps to Reproduce

  1. Setup a ListView containing elements in XAML
  2. Use EventToCommandBehavior to execute a command on the ItemTapped event
  3. Use Prism XAML navigation in the Command property for the EventToCommandBehavior
  4. The exception is thrown when tapping an item in the ListView

Expected Behavior

The navigation to occur when tapping the item.

Actual Behavior

The above exception is thrown.

Basic Information

  • Version with issue: 8.1.97
  • Last known good version: n/a
  • Xamarin.Forms version: 5.0.0.2012
  • IDE: Visual Studio 16.9.6

Reproduction Link

A Visual Studio solution that demonstrates the issue is here. Run the app on Android, tap a name in the ListView, the exception will occur.

Thanks!

@brianlagunas
Copy link
Member

Thanks for reporting this. This was never designed to work within a Behavior. For now you will have to use an ICommand in your ViewModel. I will add support for calling the NavigateTo markup extension within the Prism EventToCommand.

@Nate129
Copy link
Author

Nate129 commented Jun 24, 2021

You're welcome! I'm glad to hear that the ability to navigate via an event will be supported in XAML without the need to add any extra code to the code behind or ViewModel. It will make the task of writing code to navigate via an event like ItemTapped on a ListView cleaner and more succinct.

@dansiegel
Copy link
Member

closed by #2495

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

No branches or pull requests

3 participants