我正在使用列表框,当你单击它上面的项目时,你会看到列表框的值上标有蓝线,我想禁用它,你不能标记列表框的值和 复制粘贴它
我尝试使用IsSelected =“False”但没有成功......
<ListBox x:Name="seus" IsSelected="False" Height="115" Width="150" ItemsSource="{Binding Use}" SelectionChanged="listbox_SelectionChanged" AllowDrop="True" PreviewDrop="ListBox_PreviewDrop" />
这是列表框的事件
private void listbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is ListBox)
{
var listBox = sender as ListBox;
if (e.AddedItems.Count == 1)
{
if (listBox.SelectedItem != null)
{
var mySelectedItem = listBox.SelectedItem as User;
if (mySelectedItem != null)
{
DragDrop.DoDragDrop(listBox, mySelectedItem.Name, DragDropEffects.Copy | DragDropEffects.Move);
}
}
}
}
else
return;
}
答案 0 :(得分:0)
关闭选择确实有点棘手。但是添加一个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>
我知道这只是一半。它不会关闭复制/粘贴。