如何在WPF中更改Listbox的SelectionMode?

时间:2013-10-25 02:57:32

标签: c# wpf

问题很简单,我想在我的程序中更改Listbox的SelectionMode,但我发现它很难解决。

1 个答案:

答案 0 :(得分:2)

ListBox.SelectionMode使用您将使用的System.Windows.Controls.SelectionMode Enumeration

//Your three options
listBox1.SelectionMode = SelectionMode.Single;
listBox1.SelectionMode = SelectionMode.Extended;
listBox1.SelectionMode = SelectionMode.Multiple;

<强>的Xaml

<Grid>
    <ListBox Height="100"  SelectionMode="Extended"  HorizontalAlignment="Left" Margin="10,10,0,0" Name="listBox1" VerticalAlignment="Top" Width="120" />
    <ListBox Height="100"  SelectionMode="Multiple"   HorizontalAlignment="Left" Margin="147,10,0,0" Name="listBox2" VerticalAlignment="Top" Width="120" />
    <ListBox Height="100"  SelectionMode="Single"   HorizontalAlignment="Left" Margin="284,10,0,0" Name="listBox3" VerticalAlignment="Top" Width="120" />
</Grid>

如果你想要的不是这个,你需要更具体地解决 Exact 问题。