問題描述
我正在使用選項卡控件,我想處理 tabchanged 事件.
I'm using tab control and I want to handle tabchanged event.
我試圖使用 SelectionChanged
事件,但沒有成功.它被觸發了太多次(在加載選項卡控件或添加新選項卡之后).我只想在用戶在選項卡之間導航時處理此事件.
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.
我找到了 WPF 的解決方案(標準 WPF 選項卡控件中是否存在 Selected Tab Changed 事件),但這對 Silverlight 沒有好處.TIA.
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.
推薦答案
如果您檢查事件中 SelectedIndex
屬性的實際更改,則觸發太多次"應該不是問題.
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...
}
}
這篇關于Silverlight tabchanged 事件 - tabcontrol的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!