C# 禁用D&D中的列表框选择

C# 禁用D&D中的列表框选择,c#,wpf,xaml,mvvm,listbox,C#,Wpf,Xaml,Mvvm,Listbox,我正在使用列表框,当您单击列表框上的项目时,您会看到列表框的值上标记了蓝线,我想禁用它,您无法标记列表框的值,并且 复制粘贴它 我尝试了IsSelected=False,但没有成功 <ListBox x:Name="seus" IsSelected="False" Height="115" Width="150" ItemsSource="{Binding Use}" SelectionChanged="listbox_SelectionChanged" AllowDrop="True"

我正在使用列表框,当您单击列表框上的项目时,您会看到列表框的值上标记了蓝线,我想禁用它,您无法标记列表框的值,并且 复制粘贴它

我尝试了IsSelected=False,但没有成功

<ListBox x:Name="seus" IsSelected="False"  Height="115" Width="150" ItemsSource="{Binding Use}" SelectionChanged="listbox_SelectionChanged" AllowDrop="True" PreviewDrop="ListBox_PreviewDrop" />

关闭选择确实有点棘手。但是添加ItemContainerStyle可以:

<ListBox.ItemContainerStyle>
    <Style TargetType="ListBoxItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Border>
                        <TextBlock HorizontalAlignment="Stretch" Text="{Binding}" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ListBox.ItemContainerStyle>

我知道这只是半途而废。它不会关闭复制/粘贴。

仅在行之间,否则返回;在这种情况下是一个冗余控制流跳转语句。你可以简单地移除它。
<ListBox.ItemContainerStyle>
    <Style TargetType="ListBoxItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Border>
                        <TextBlock HorizontalAlignment="Stretch" Text="{Binding}" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ListBox.ItemContainerStyle>