我正在尝试在列表框中实现拖放功能(在列表框中)。对于拖动,我使用的是 Thumb 控件(Mythumb 是从 thumb 继承的类)
所以我将项目面板设置为 Canves 并将列表框项目的样式设置为以下
<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>
拖放工作正常,但拇指不允许选择项目。检查后我发现 mousedown 事件没有触发。有没有办法以通常的方式启用选择项目?