public ImageButton CreateImageButton(object view, BitmapSource bitmapSource) { ImageButton imageButton = null; Image newImage = CreateImageForButton(bitmapSource); if (newImage != null) { imageButton = new ImageButton(); imageButton.Content = newImage; imageButton.Style = _tabControl.ContentTabImageButtonStyle; object title = null; if (_contentTabView.Views.TryGetValue(view, out title)) { imageButton.Title = title == null ? string.Empty : title.ToString(); } imageButton.Click += new RoutedEventHandler(imageButton_Click); imageButton.ApplyTemplate(); SetupCloseButton(view, imageButton); } return imageButton; }
private void SetupCloseButton(object view, ImageButton imageButton) { Button closeButton = imageButton.Template.FindName("PART_CloseButton", imageButton) as Button; FabTabItem currentItem = view as FabTabItem; if (currentItem == null) { currentItem = _tabControl.ItemContainerGenerator.ContainerFromItem(view) as FabTabItem; } if (currentItem.ShowCloseButton) { closeButton.Click += new RoutedEventHandler(closeButton_Click); closeButton.Command = new RoutedCommand(); CommandBinding b = new CommandBinding(closeButton.Command, new ExecutedRoutedEventHandler(imageButtonCommandExecuted)); imageButton.CommandBindings.Add(b); } else { closeButton.Visibility = Visibility.Hidden; } }