Posts Tagged ListBox

WPF: Non-selectable ListBoxItem and ListViewItem

Problem

Sometimes in WPF you want to have a list of items contained in a ListBox (or ListView) that you don’t want to be selectable. You could set those items to be disabled, by assigning IsEnabled to False, but that may interfere with styles among other things. You could also (probably the best idea) use a ItemsControl, from which the ListBox derives, that doesn’t include selectable-items functionality. However, for whatever reason, you may just want to use a ListBox (or ListView) instead.

Solution

Read the rest of this entry »

, , , , , , , , ,

4 Comments

Auto-Select First Item Using XAML for Selector-Derived Controls (ListBox, ListView, TabControl, etc)

Problem

When your application has a control on it that derives from Selector and has no items on load nothing is selected. During run-time when the user is clicking around and adds items to the Selector-derived control, you would assume that the control would automatically select the first item because that only makes sense. However, your assumption and mine would be wrong; this is not the behavior at all. Instead the selector will still have no items selected. This means in order to get this “auto-select first item” behavior, you have to do it yourself. Luckily its an easy fix as shown below.

Read the rest of this entry »

, , , , , ,

7 Comments