Selecting a Textbox Item in a Listbox does not change the selected item of the listbox

后端 未结 15 1404
清酒与你
清酒与你 2020-11-27 04:10

I Have a wpf Listbox that display\'s a list of textboxes. When I click on the Textbox the Listbox selection does not change. I have to click next to the TextBox to select th

15条回答
  •  情歌与酒
    2020-11-27 04:48

    Your not very specific about your initial situation. But i assume that you use DataBinding and an ItemTemplate. Thats imho an easy way to do this, as well if your beginner on this topic. This should work:

    
       
          
             
          
       
    
    

    private void TextBox_GotFocus(object sender, RoutedEventArgs e)
    {
       myListBox.SelectedItem = (sender as TextBox).Tag; /* Maybe you need to cast to the type of the objects contained in the collection(bound as ItemSource above) */
    }
    

提交回复
热议问题