Search code examples
.netsilverlighttabcontrol

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 I think are not longer available for Silverlight)


Solution

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