I have created TabItems in silverlight
where each tab display some text. When i change the text then it show asterisk at the Header of TabItem with header name.
Now what i want to achieve is : suppose i made a change on the current TabItem text display then when i switch from the one tab to another tab item then it must show a pop up saying "do you wanna save the changes done ?"
Does silverlight provide any facility in TabItem to notify when there is change in the TabItem (I mean when switching is done from one tabitem to another) ?
My code to do so is:
ObservableCollection < TabItem > result = new ObservableCollection < TabItem > (); RotateTransform rt = new RotateTransform() { Angle = 90 }; foreach(TotalFiles vm in source) { if (vm == null) continue; ObservableCollection < TabItem > subSource = new ObservableCollection < TabItem > (); Grid g = new Grid(); g.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); g.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }); TextBox tb = generateCodeTextBox(); tb.TextChanged += vm.CodeTextChanged; Grid.SetRow(tb, 0); g.Children.Add(tb); Grid panel = actionPanel(vm); Grid.SetRow(panel, 1); g.Children.Add(panel); subSource.Add(new TabItem() { Header = new LayoutTransformer() { LayoutTransform = rt, Content = " Code " }, Content = g }); subSource.Add(new TabItem() { Header = new LayoutTransformer() { LayoutTransform = rt, Content = " XML parameters " }, Content = generateXmlTextBlock() }); TabItem previewItem = new TabItem() { Header = new LayoutTransformer() { LayoutTransform = rt, Content = " Preview parameters " } }; sv.SetBinding(ScrollViewer.ContentProperty, new Binding("Preview")); previewItem.Content = sv; subSource.Add(previewItem); //this stack panel"sp" will contain filename at top and also "x" buttin which on clicking will cose that tab containing that text. StackPanel sp = new StackPanel() { Orientation = Orientation.Horizontal }; sp.Children.Add(generateFileNameHeaderTabLabel()); sp.Children.Add(new Button() { Content = "x", Height = 16, Width = 16, Padding = new Thickness(0), Margin = new Thickness(10, 0, 0, 0), Command = vm.CloseProgramCmd }); result.Add(new TabItem() { Header = sp, Content = new TabControl() { ItemsSource = subSource, TabStripPlacement = Dock.Right }, DataContext = vm }); }
For example if i have two tabitems after this code like this:
After when i make change it adds asterisk at top. When i switched to another tabitem(by clicking on it:
After when i make change it adds asterisk at top. When i switched to another tabitem(by clicking on it). like this:
On switching here from one tab item to another must pop up a message that do you wanna save the change in the previous tab.How to get notification of switching the tab ?