Marcom
Marcom

Reputation: 4741

wpf selecting controls inside a listbox

I have a textbox and some labels inside the data template of bounded listbox.

When I click on any label the whole item is highlighted in blue, but when I click directly on a different textbox the selection does not change.

Is there a way to make the selection of the listbox change even when a textbox is clicked?

thanks

Upvotes: 0

Views: 202

Answers (2)

Dan Puzey
Dan Puzey

Reputation: 34200

The reason is because the TextBox handles the click event in order to receive focus. There are a number of ways to handle this, including but not limited to:

  • stop the TextBox handling mouse events (which prevents the user from focussing it using the mouse)
  • use an eventhandler when the TextBox gains focus (or PreviewClick or similar), to select the parent ListItem

Upvotes: 0

sll
sll

Reputation: 62484

This is what I've exactly asked few days ago, see post: "WPF: Trigger SelectedIndex changed whilst clicking on any control within a ListBoxItem area"

basically there are few solutions, using code behind and XAML, but I've not verified latter approach yet

Upvotes: 1

Related Questions