I have a ItemsControl(A). ItemSourece is a Class "Account".It contains some controls and another ItemsControl(B).
ItemsControl(B) includes some CheckBox. It's ItemSourece is ObservableCollection included in Class "Account". CheckBox's Content is binding to Content. CheckBox's IsChecked is bindind to IsChecked.
Now when I click CheckBox, I want to get ID and User in Class "Account", but I don't know hot to get them. I already try to use
private void CheckBox_Click(object sender, RoutedEventArgs e)
{
CheckBox checkBox = sender as CheckBox;
var parentElement = (ContentPresenter)VisualTreeHelper.GetParent(checkBox);
}
but it still can't get parent.
Althouth runtime can show parentElement.VisualParent, but actually it is not work.

Please help me! Thanks!

@RickyChen - I see your problem.
AuthorityCheckBoxbinds to your visual checkboxes. When you click on a checkbox, there isn't any link back to theAuthorityCheckBox.What you can do is abuse the
Tagproperty of your checkbox and place theAuthorityCheckBoxreference there.Adjust your your
AuthorityCheckBoxclass so it containspublic Account Parentthat is assigned in the constructor. This way you can easily get theAuthorityCheckBoxparent:The event handler then looks like this: