2012-04-12 187 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

相關問題