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

  • SEARCH
  • Home
  • 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 7653151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:57:19+00:00 2026-05-31T11:57:19+00:00

I am trying to use AttachedCommandBehavior V2 to translate ListBoxItem events such as double

  • 0

I am trying to use AttachedCommandBehavior V2 to translate ListBoxItem events such as double click into commands that are execute against the view model.

I want to fire commands for multiple events, this is the example code I am trying to emulate:

<Border Background="Yellow" Width="350" Margin="0,0,10,0" Height="35" CornerRadius="2" x:Name="test">
    <local:CommandBehaviorCollection.Behaviors>
            <local:BehaviorBinding Event="MouseLeftButtonDown" Action="{Binding DoSomething}" CommandParameter="An Action on MouseLeftButtonDown"/>
            <local:BehaviorBinding Event="MouseRightButtonDown" Command="{Binding SomeCommand}" CommandParameter="A Command on MouseRightButtonDown"/>
    </local:CommandBehaviorCollection.Behaviors>
    <TextBlock Text="MouseDown on this border to execute the command"/>
</Border>

Since I want to apply that to a ListBoxItem, I am trying to do it through a style by doing:

<ListBox.ItemContainerStyle>
    <Style>
        <Setter Property="acb:CommandBehaviorCollection.Behaviors">
            <Setter.Value>
                <acb:CommandBehaviorCollection>
                    <acb:BehaviorBinding Event="MouseDoubleClick" Command="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ListBox}}" CommandParameter="{Binding}"/>
                    <acb:BehaviorBinding Event="KeyUp" Command="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ListBox}}" CommandParameter="{Binding}"/>
                </acb:CommandBehaviorCollection>
            </Setter.Value>
        </Setter>
    </Style>
</ListBox.ItemContainerStyle>

But I get a compile error with that code that says error MC3089: The object 'CommandBehaviorCollection' already has a child and cannot add 'BehaviorBinding'. 'CommandBehaviorCollection' can accept only one child. Line 39 Position 11.

Also if I comment out one of the BehaviorBindings then it compiles but I get a runtime xaml load exception saying “Value cannot be null. Parameter name: property”, so I’m not sure if I’m even taking the correct approach.

Can anyone provide an example of the correct syntax to set multiple behavior bindings on a ListBoxItem?

  • 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-05-31T11:57:20+00:00Added an answer on May 31, 2026 at 11:57 am

    My solution uses interaction triggers and the ItemTemplate not the ItemContainerStyle.
    This invokes a mouse double click or key up command in the text box, not the whole list box item.

    <UserControl.Resources>
        <DataTemplate DataType="{x:Type ViewModel:DataItem}" x:Key="ItemTemplate">
            <ContentControl>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="MouseDoubleClick">
                        <i:InvokeCommandAction Command="{Binding DoubleClickCommand}"/>
                    </i:EventTrigger>
                    <i:EventTrigger EventName="KeyUp">
                        <i:InvokeCommandAction Command="{Binding KeyUpCommand}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <TextBox Text="{Binding Name}">
                </TextBox>
            </ContentControl>
        </DataTemplate>
    </UserControl.Resources>
    
    <ListBox x:Name="listBox" ItemTemplate="{StaticResource ItemTemplate}" ItemsSource={Binding Items} />
    

    Where DataItem is something like

    class DataItem : INotifyPropertyChanged
    {
       public string Name{get;set}
       .. etc
    }
    

    and the view model set on the DataContext has an IList<DataItems> Items{get; private set} property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a regex that I'm trying use to validate against strings. Trying to
I'm a little confused here, I am trying use a partial view in a
I'm trying use eco for client-side templating. I have multiple .eco templates that I'd
I have a 3rd party DLL that I am trying to use in a
I'm trying use double type in openCL, but doesn't work anyway, i want use
I am trying use the jQuery table sorter plugin for a table that is
I am trying use the mysql connector in c++ in ubuntu. It appears that
I was trying use the code shown below to plot in such a way
I was trying use a set of filter functions to run the appropriate routine,
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on

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.