Silverlight tabchanged event - tabcontrol

本文关键字:tabcontrol event tabchanged Silverlight | 更新日期: 2023-09-27 18:08:19

我正在使用tab控件,我想处理tabchanged事件。

我试图使用SelectionChanged事件没有运气。它被触发太多次(加载tab控件后,或添加新的选项卡)。我希望仅当用户在选项卡之间导航时处理此事件。

我已经找到了WPF的解决方案(在标准WPF选项卡控件中是否有选定选项卡更改事件),但它对Silverlight没有好处。TIA。

Silverlight tabchanged event - tabcontrol

如果您检查事件中SelectedIndex属性的实际更改,则触发"too many times"应该不是问题。

private int LastSelectedTab = -1;
void tab_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    TabControl tab = sender as TabControl;
    if (this.LastSelectedTab != tab.SelectedIndex)
    {
        this.LastSelectedTab = tab.SelectedIndex;
        // Now do your thing...
    }
}