This project is read-only.

ListBoxEx.Command accepts DoubleClick from anywhere in list, including scrollbar

Jun 10, 2014 at 8:28 PM
I'm using the Workplace theme, ListBox control. In the control, I set the ListBoxEx.Command like so:
   <ListBox ItemsSource="{Binding ViewSource.View}"
                 SelectedItem="{Binding SelectedItem}"
                 Grid.Row="0">
        <c:ListBoxEx.Command>
            <Binding Path="OpenCommand" />
        </c:ListBoxEx.Command>
Users can double-click on an item in the list and the command executes. Unfortunately, it also executes when the scrollbar or ListColumn header is double-clicked.

Workplace-Control-ListBox.xaml has the following setter, so I assume it was intended to set the DoubleClick action on the ListBox as a whole. Not all have headers, of course, but most would have scrollbars, I'd think.
<Style TargetType="ListBox" x:Key="Workplace-Control-ListBox" BasedOn="{StaticResource {x:Type ListBox}}">
        <Style.Resources>
            <Style TargetType="ListBoxItem">
                <Setter Property="c:ListBoxItemEx.SelectItemWhenFocusWithin" Value="True" />
                <Setter Property="Template" Value="{DynamicResource Workplace-ListBoxItem}" />
            </Style>
            <Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
                <Setter Property="TextTrimming" Value="CharacterEllipsis" />
            </Style>
        </Style.Resources>

        __<Setter Property="c:ListBoxEx.CommandTrigger" Value="DoubleClick" />__
I'm going to do what I want (allow users to double-click on items in a ListBox, but not in the scrollbars or header. But, in case I'm misusing the control, or if it's a bug, thought I'd post this.
Jun 11, 2014 at 1:49 PM
Hello Nancy,

I believe that if you were to look at how a ListBox was constructed in WPF you would find that the ScrollBar (a ScrollViewer) is actually a property of the ListBox, therefore it would be considered to be part of, and act on the actions applied to the ListBox (in this case your DoubleClick action).

I agree that users would not expect that double clicking on a ScrollBar would do anything, but when applying a command to the entire ListBox it is a correct action, not a bug. Think of the case where another type of command is applied, such as grabbing the ListBox to move it, or click to close or hide it, in that instance you would expect the ScrollBar to trigger those commands.

Jeff Etter
Marked as answer by NancyFolsom on 6/12/2014 at 8:45 AM
Jun 12, 2014 at 3:39 PM
FYI: I have added this to my internal to-do list to see if there is something we can do about this.


Markus
Jun 12, 2014 at 4:45 PM
Thanks for the reply, Jeff. I agree and understand. I think my main point was that since the property is set in the theme, I, as a user, make use of it. It's a very, very small issue, though.
Jun 12, 2014 at 4:45 PM
Thanks, Markus.
Aug 31, 2016 at 7:10 PM
Has anyone encountered good workaround which only activates the command when a ListBoxItem is clicked?
Sep 1, 2016 at 5:55 PM
@mcargille--It's been a while and I don't still have the project at hand, but, IIRC, I never found a solution for the issue. If I get some time I'll dig it out from the archives and see what, if anything, I resolved.