Trying find how to cancel TabControl.SelectionChanged in silverlight

雨燕双飞 提交于 2019-12-11 01:12:53

问题


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 wich i think are not longer available for silverlight)


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/6915432/trying-find-how-to-cancel-tabcontrol-selectionchanged-in-silverlight

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