Trying find how to cancel TabControl.SelectionChanged in Silverlight
I am trying figure out how cancel this event in Silverlight, sadly I didn't find any useful link with the solution. (I saw some post for wpf which开发者_Python百科 I think are not longer available for Silverlight)
Here is the bare bones of it:-
bool cancellingTabSelectionChange = false;
private void tabControl1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.RemovedItems.Count > 0 && !cancellingTabSelectionChange)
{
cancellingTabSelectionChange = true;
((TabControl)sender).SelectedItem = e.RemovedItems[0];
cancellingTabSelectionChange = false;
}
}
You would need to add the extra criteria the would allow a change to take place since the above code would always block a change of tab.
As i know there is not straight way to cancel it. You can disable control if dont want change tab, or set selectedtab to which you want after selectionchanged fired.
private void tabControl1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
tabControl1.SelectedIndex = [index of tab]
}
精彩评论