2012-04-12 124 views
0

我希望能够判断哪个选项卡是Microsoft功能区中的活动选项卡,以相应地更改内容显示。检测Microsoft Ribbon中的活动选项卡是否已更改

我该怎么做?

这就是我想出了:

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) 
    { 

    } 

,但必须有一个更好的方式来做到这一点。在那儿?

回答

2

功能区从ItemsControl继承,因此如果绑定到SelectedItem属性,您将收到有关当前Tab变化的通知。

+0

绝妙的主意!谢谢! – 2012-04-12 12:52:22

相关问题