我正在查看https://referencesource.microsoft.com/中的WPF源代码,但是我无法弄清楚在单击TabItem后如何选择它。
如何监听点击?我假设代码的某处侦听选项卡项上的点击。
我在 TabItem.cs 中找到的只是这个,但是它没有选择TabItem:
/// <summary>
/// This is the method that responds to the MouseLeftButtonDownEvent event.
/// </summary>
/// <param name="e"></param>
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
// We should process only the direct events in case TabItem is the selected one
// otherwise we are getting this event when we click on TabItem content because it is in the logical subtree
if (e.Source == this || !IsSelected)
{
if (SetFocus())
e.Handled = true;
}
base.OnMouseLeftButtonDown(e);
}
我需要了解的是它在代码中侦听鼠标单击的位置。我知道TabControl是从Selector派生的,但是我找不到所选项目的设置方式。