0

I've noticed a strange bug when creating a desing with xaml:

sometimes I'm able to "select" controls the way I'd select text.

Normally the controls would look like this:

enter image description here

while if accidental selection happens, it looks like this:

enter image description here

Why does this happen, and how do I prevent it?

UPDATE

Here's the controls that I'm using: TreeView->Expander->StackPanel->DataGrid

Based on the answers, the problem probably originates from TreeView.

How do I prevent TreeView items from being selected?

Arsen Zahray
  • 24,367
  • 48
  • 131
  • 224
  • 1
    I'm guessing your using a ListBox that has a SelectedItem rather than an ItemsControl? If you don't need a SelectedItem use an ItemsControl. – Dave S Apr 20 '12 at 14:21

2 Answers2

2

That should only be the case if the control is inside something selectable like a ListBoxItem, to prevent that use ItemsControls instead of subclasses of Selector (e.g. ListBox). If that is not it i don't know what is going on as i have never seen something like that.


Judging from your edit you appear to have TreeViewItems, you could either override the respective brush-keys to hide the selection or add a TreeView.ItemContainerStyle which changes the Template to something which will not show the selection in the first place.

Community
  • 1
  • 1
H.B.
  • 166,899
  • 29
  • 327
  • 400
2

It appears your control is based off a listbox which supports being able to select items in that manner. Perhaps change the underlying control to be based on an 'items control' instead.

Edit:

Tree view has the same behavior allowing to select an item. See this question...

Disable WPF TreeView (or TreeViewItem) selection?

Community
  • 1
  • 1
Kevin DiTraglia
  • 25,746
  • 19
  • 92
  • 138