Trigger SelectedIndex changed whilst clicking on any control within a ListBoxItem area

前端 未结 4 887
广开言路
广开言路 2020-12-18 11:26

I\'ve a data template for ListBoxItem which contains of few buttons, and few custom controls like Grid or Chart. Each button is bound to an appropriate command handler, Sel

4条回答
  •  抹茶落季
    2020-12-18 12:12

    Can you not set the item as the selected item in the bound command? If your list Item viewmodel has access to whatever the ListBoxes viewmodel is, you should be able to set the property that you have bound there.

    Private Sub ButtonClickExecute()
         ListBoxVM.SelectedItem = Me.MyModelItem
    End Sub
    

    I have done this on occasion and it has worked quite well, so long as the SelectedItem bound property is read/write, PropertyChangeNotification is working.

    If your ViewModel and Model don't support this, let me know and we can try another way.

    Whoops, did not immediately notice the C# tag. That should be:

    ListBoxVM.selectedItem = this.myModelItem;
    

提交回复
热议问题