private ButtonWithObject CreateCloseButton(object uc) { var newButton = new ButtonWithObject { Content = new Image { Source = new BitmapImage(new Uri(@"..\img\x-icon.png", UriKind.Relative)), VerticalAlignment = VerticalAlignment.Center }, Object = uc, Width = 20, Height = 20, VerticalContentAlignment = VerticalAlignment.Center, HorizontalContentAlignment = HorizontalAlignment.Center, Style = (Style)FindResource("MyButton"), }; newButton.Click += RemoveFromBarView_Click; return(newButton); }
private ButtonWithObject CreateViewBarButton(string name, string content, int width, object insideObject, bool isSelected, RoutedEventHandler operation) { var brush = (Brush)FindResource("MyAzure"); var style = (Style)FindResource("MyButton"); if (isSelected) { brush = (Brush)FindResource("MyWhite"); style = (Style)FindResource("MyButtonBarView"); } var columnDefinition1 = new ColumnDefinition() { Width = new GridLength((width - 30 < 0)?0:width - 30), }; var columnDefinition2 = new ColumnDefinition() { Width = new GridLength(20), }; var grid = new Grid { Width = (width - 10 < 0) ? 0 : width - 10, HorizontalAlignment = HorizontalAlignment.Center, Background = (Brush)FindResource("Transparent"), ColumnDefinitions = { columnDefinition1, columnDefinition2 }, }; var label = new Label { Content = content, HorizontalAlignment = HorizontalAlignment.Center, Background = (Brush)FindResource("Transparent"), Foreground = brush, }; var closeButton = CreateCloseButton(insideObject); closeButton.HorizontalAlignment = HorizontalAlignment.Right; label.SetValue(Grid.ColumnProperty, 0); closeButton.SetValue(Grid.ColumnProperty, 1); grid.Children.Add(label); grid.Children.Add(closeButton); var button = new ButtonWithObject { Name = name, Content = grid, Object = insideObject, Context = label, }; button.Click += operation; if (!isSelected) { button.MouseEnter += MouseEnter_Event; button.MouseLeave += MouseLeave_Event; } button.Width = width; button.Style = style; return(button); }