Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8745191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:58:00+00:00 2026-06-13T11:58:00+00:00

I have the following list view in a user control. I would like to

  • 0

I have the following list view in a user control. I would like to register a double click on the entire row. When a double click is registered, I would like to call an ICommand in my view model.

Does anyone know how I can do this?

I know there are other posts about this and I have tried the solutions found in them (using both MVVM Light and AttachedCommandBehavior) but either the double click is simply not registered or it tries to call the ICommand on my TVSeries object which is my model and which holds the data presented in the rows.

This is my list view:

<ListView Height="456"
          HorizontalAlignment="Left"
          Margin="12,12,0,0" 
          VerticalAlignment="Top"
          Width="488"
          ItemsSource="{Binding Path=Library}"
          SelectedItem="{Binding Path=SelectedTVSeries}">

    <ListView.View>

        <GridView>

            <GridViewColumn Header="Name"
                            Width="Auto">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Name}"
                                   FontWeight="Bold" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>

            <GridViewColumn Header="Year"
                            Width="Auto">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Year}" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>

            <GridViewColumn Header="Genre"
                            Width="Auto">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Genre}" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>

        </GridView>

    </ListView.View>

</ListView>

UPDATE

When using AttachedCommandBehavior I will get the following error:

NullReferenceException was unhandled

Object reference not set to an instance of an object.

The error occurs on the following lines (which are a part of AttachedCommandBehavior):

/// <summary>
/// Executes the strategy
/// </summary>
public void Execute()
{
   strategy.Execute(CommandParameter);
}

I use ACB like below. First I declare my style for the ListViewItem.

<– language: xml –>

<UserControl.Resources>
    <Style x:Key="LibraryListViewItemStyle"
           TargetType="{x:Type ListViewItem}">
        <Setter Property="acb:CommandBehavior.Event" Value="MouseDoubleClick" />
        <Setter Property="acb:CommandBehavior.Action" Value="{Binding RelativeSource={RelativeSource AncestorType=ListView}, Path=DataContext.TVSeriesDoubleClickedCommand}" />
        <Setter Property="acb:CommandBehavior.CommandParameter" Value="{Binding }" />
    </Style>
</UserControl.Resources>

Then I set the ItemContainerStyle on my list view to the style.

<ListView Height="456"
          HorizontalAlignment="Left"
          Margin="12,12,0,0" 
          VerticalAlignment="Top"
          Width="488"
          ItemsSource="{Binding Path=Library}"
          SelectedItem="{Binding Path=SelectedTVSeries}"
          ItemContainerStyle="{StaticResource LibraryListViewItemStyle}">

...

</ListView>

Does anyone know how to fix this? This is really the closest I have been.

** UPDATE: Solution**

The above error occurred, because I have configured AttachedCommandBehavior to expect an action, but I had implemented a command. Changing from the following

<Setter Property="acb:CommandBehavior.Action" Value="{Binding RelativeSource={RelativeSource AncestorType=ListView}, Path=DataContext.TVSeriesDoubleClickedCommand}" />

To the following

<Setter Property="acb:CommandBehavior.Command" Value="{Binding RelativeSource={RelativeSource AncestorType=ListView}, Path=DataContext.TVSeriesDoubleClickedAction}" />

That solved the error.

However, I found that I prefer using an action so I kept acb:CommandBehavior.Action and changed my implementation:

public Action<object> TVSeriesDoubleClickedAction
{
    get
    {
        return new Action<object>(tvSeries => Console.WriteLine("*** Double clicked fired: {0}", ((TVSeries)tvSeries).Name));
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:58:01+00:00Added an answer on June 13, 2026 at 11:58 am

    or it tries to call the ICommand on my TVSeries object which is my model and which holds the data presented in the rows.

    This would happen because you have your binding to your ICommand set incorrectly. I would suggest going back to one of the solutions you’ve tried where it was calling the ICommand on the TVSeries object and try changing your binding to something similar to this:

    Binding="{Binding RelativeSource={RelativeSource AncestorType=ListView}, Path=DataContext.YourCommandName}"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following ListView with a custom list item: I would like to
I have a list view.Each row of the this listview is the following layout.How
I have a list view comprised of the following: // Add column headers for
I have a list view as following: <ListView x:Name=lvLedger Height={Binding Path=GridHight, ElementName=ledgerList} Width={Binding Path=GridWidth,
I have a view that renders a list elements using the following template :
I have the following xaml which resides in a wpf user control - <Grid>
I have a user control that should serve as container and it looks like
I have a list view where the list items have the following background drawable
I have the following code in my index view. latest_entry_list = Entry.objects.filter(is_published=True).order_by('-date_published')[:10] for entry
Helo. I have the following requirement: I have a list (ListView or Spinner depends

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.