检测功能区中的活动选项卡是否已更改Microsoft

本文关键字:是否 Microsoft 选项 功能区 活动 检测 | 更新日期: 2023-09-27 18:30:46

我希望能够知道哪个选项卡是功能区中的活动选项卡Microsoft以相应地更改内容呈现。

我该怎么做?

这是我想到的:

    public MainWindow()
    {
        InitializeComponent();
        // Insert code required on object creation below this point.
        new Thread(() =>
        {
            int lastIndex = int.MinValue;
            while (true)
            {
                Thread.Sleep(100);
                int newIndex = -1;
                this.Dispatcher.Invoke(DispatcherPriority.Normal,
                    new Action(() =>
                    {
                        newIndex = Ribbon.SelectedIndex;
                    }));
                if (newIndex != lastIndex)
                {
                    lastIndex = newIndex;
                    var index = lastIndex;
                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) (() =>OnCurrentTabChanged(index)));
                }
        }){ IsBackground=true}.Start();
    }
    void OnCurrentTabChanged(int tabIndex)
    {
    }

但必须有更好的方法来做到这一点。有吗?

检测功能区中的活动选项卡是否已更改Microsoft

功能

区继承自 ItemsControl,因此,如果您绑定到 SelectedItem 属性,您将收到有关当前 Tab 更改的通知。