Thum not allowing to fire leftMouseDown

I am trying to implement dragdrop functionality in Listbox(with in the listbox). For dragging i am using Thumb control (Mythumb is the class inherited from thumb)

so i have set the items panel to Canves and set the style for list box item to following

           <Style  TargetType="{x:Type ListBoxItem}">                    
                <Setter Property="Width" Value="150" />
                <Setter Property="Height" Value="150" />
                <Setter Property="Margin" Value="5,2" />
                <Setter Property="Padding" Value="3" />
                <Setter Property="dcc:OutputConfigurationPanel.Left" Value="{Binding  Left}"></Setter>
                <Setter Property="dcc:OutputConfigurationPanel.Top" Value="{Binding Top}"></Setter>
                <Setter Property="IsSelected" Value="{Binding IsSelected}"></Setter>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                <Grid DockPanel.Dock="Bottom" >
                                    <Grid>
                                    <Border BorderBrush="Black" Background="Black">                                            
                                        <ContentPresenter x:Name="ContentHost" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />                                            
                                    </Border>
                                    <MythumbTemplate="{StaticResource MoveThumbTemplate}" Cursor="Hand" />
                                </Grid>
                                </Grid>                                
                            <ControlTemplate.Triggers>
                                <Trigger Property="Selector.IsSelected" Value="True">
                                    <Setter  Property="Background" Value="#FF233B00" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

The drag drop is working fine but the thumb doesn't allow the item to be selected. After checking i found that the mousedown event is not firing. Is there a way to enable the select the items in usual ways?


A Thumb will always eat mouse clicks, same as button.

As I see it, you have two options:

  • From the code of the thumb, search up until you find the list box item and then set it's IsSelected property to true.

  • Scrap the thumb and create a Behavior that deals with dragging but doesn't handle mouse events (ie doesn't set e.Handled=true; ) - this will preserve list box functionality.

  • Option 1 is probably faster, but I'd strongly consider to go with option 2 - less meddling with core controls functionality = better.

    链接地址: http://www.djcxy.com/p/59902.html

    上一篇: 取消选择单选列表框

    下一篇: 这不允许发射leftMouseDown