0

I have a ListView with the ListViewItem ControlTemplate set to a custom UserControl. The UserControl consists of several TextBoxes and TextBlocks. Clicking on a TextBlock will update the SelectedItem, but clicking a TextBox will not. How do I get the SelectedItem to update when any control in the UserControl gets focus?

Mike
  • 620
  • 11
  • 16

1 Answers1

0

The routedEvent in your TextBox is capturing the bubbling routed event. Where it is telling that it doesn't need to bubble any further. You can tell the text box that the event is not handled in the RoutedEventArgs, and use the tunneling event for the textbox interaction.

This hooked on to the text box will allow the event to bubble up to the ListView.

private static void MouseDown(object sender, MouseWheelEventArgs e)
{
   e.Handled = false;
}
Matt Wilkinson
  • 592
  • 2
  • 13
  • I tried this but the method isn't running when I mouse down on the TextBox so it seems like the event isn't firing. – Mike Apr 21 '16 at 18:31
  • I am sorry, I forgot about a caveat in the bubbling architecture. You read about it here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/727b7569-28f9-4168-8dd0-519e15aa8613/listboxselectionchanged-gets-fired-when-listbox-item-is-changed?forum=wpf – Matt Wilkinson Apr 21 '16 at 18:49
  • So, you will need to handle the selection call, for the list view manually when they click on the text box. I will change my example above when I try it out on my sample project i created. – Matt Wilkinson Apr 21 '16 at 18:50