【问题标题】:Silverlight tabchanged event - tabcontrolSilverlight tabchanged 事件 - tabcontrol
【发布时间】:2011-09-09 09:43:01
【问题描述】:

我正在使用选项卡控件,我想处理 tabchanged 事件。

我试图使用SelectionChanged 事件但没有运气。它被触发了太多次(在加载选项卡控件或添加新选项卡之后)。 我只想在用户在选项卡之间导航时处理此事件。

我找到了 WPF (Is there Selected Tab Changed Event in the standard WPF Tab Control) 的解决方案,但它对 Silverlight 没有好处。 TIA。

【问题讨论】:

    标签: c# silverlight tabs tabcontrol


    【解决方案1】:

    如果您检查事件中SelectedIndex 属性的实际更改,则触发“太多次”应该不是问题。

    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...
        }
    }
    

    【讨论】:

    • 如果您想要一个通用修复子类 TabControl 并实现您自己的事件,该事件只能由该类中的上述代码调用...SelectionActuallyChangedByAHuman? :)
    猜你喜欢
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多