Silverlight tabchanged event - tabcontrol

ぐ巨炮叔叔 提交于 2019-12-20 04:52:30

问题


I'm using tab control and I want to handle tabchanged event.

I was trying to use SelectionChanged event with no luck. It's being fired too many times (after loading tabcontrol, or adding new tab). I would like to handle this event only when user navigates between tabs.

I have found solution for WPF (Is there Selected Tab Changed Event in the standard WPF Tab Control) but it's no good for Silverlight. TIA.


回答1:


Firing "too many times" should not be a problem if you check for an actual change to the SelectedIndex property in the event.

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


来源:https://stackoverflow.com/questions/7359765/silverlight-tabchanged-event-tabcontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!