SelectionMode Enumeration (System.Windows.Controls)

Switch View :
ScriptFree
.NET Framework Class Library
SelectionMode Enumeration

Defines the selection behavior for a ListBox.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
Syntax

Visual Basic
Public Enumeration SelectionMode
C#
public enum SelectionMode
Visual C++
public enum class SelectionMode
F#
type SelectionMode
XAML Attribute Usage
<object property="enumerationMemberName" .../>
Members

Member name Description
Single The user can select only one item at a time.
Multiple The user can select multiple items without holding down a modifier key.
Extended The user can select multiple consecutive items while holding down the SHIFT key.
Remarks

Set the SelectionMode property to one of the SelectionMode values to specify whether the user can select more that one item in a list box.

Examples

The following example sets the SelectionMode property to SelectionMode.Multiple.

XAML

<ListBox SelectionMode="Multiple">
  <DockPanel>
    <Image Source="data\cat.png"/>
    <TextBlock>CAT</TextBlock>
  </DockPanel>
  <DockPanel>
    <Image Source="data\dog.png"/>
    <TextBlock>DOG</TextBlock>
  </DockPanel>
  <DockPanel>
    <Image Source="data\fish.png"/>
    <TextBlock>FISH</TextBlock>
  </DockPanel>
</ListBox>


Version Information

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also

Reference

Community Content

Marque IV
Actually, you're wrong!
Actually, you're wrong.  The DockPanel is actually the correct control to use for this as doing so much better handles things like text trimming which a StackPanel in a listbox with default properties doesn't, because there is no horizontal constraints. (You'd have to disable horizontal scrolling on the listbox to get a stackpanel to properly trim text (yes... even if there is no horizontal scrollbar shown, that matters because of the measure and arrange steps.))  Using a DockPanel avoids that.  Besides, DockPanel is a pretty lightweight control compared to others anyway.  Not as much as StackPanel, but it doesn't have the same issues as just described.

Marque IV
Bad example using DockPanel without docking
Very Bad Example: There is no reason to use the DockPanel in the example since there is no docking. Should be fixed to use a lighter wieght panel such as a StackPanel $0$0 $0 $0MD: Actually, using the DockPanel is *far* superior to a StackPanel when used within a listbox as a StackPAnel doesn't properly trim text since Infinity is passed in as the width during the arrange pass.  That is unless you explicitly disable horizontal scrolling on the ListBox (Note: That matters even if nothing actually would cause a horizontal scrollbar to appear. Again, that has to do with what values are passed in for the width of the MeasureOverride pass... none of which you have to deal with if you're using a DockPanel instead of a StackPanel.$0