在 WPF TabControl 中,默认行为是在按下鼠标时更改选定的选项卡。
在我的应用程序中,更改选项卡有时会调整大小,有时会在另一个用户控件上调用鼠标弹起事件,因为选项卡控件已移动。
如果我可以将标签页设置为仅在鼠标松开而不是鼠标按下时切换,这将解决问题。
最佳答案
您可以像这样使用自定义 TabItem:
public class MyTabItem : TabItem {
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) {
if (e.Source == this || !this.IsSelected)
return;
base.OnMouseLeftButtonDown(e);
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) {
if (e.Source == this || !this.IsSelected)
base.OnMouseLeftButtonDown(e); // OR just this.Focus(); OR this.IsSeleded = true;
base.OnMouseLeftButtonUp(e);
}
}
关于c# - WPF TabControl 如何在鼠标向上而不是鼠标向下时更改 Tab?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6205361/