Пример #1
0
        public DragGrip GetItem(string name, string text, TranslateTransform translateTransform,
                                double width, Brush backgound, Thickness margin, string contextMenuName)
        {
            var newItem = new DragGrip
            {
                Name            = name,
                RenderTransform = translateTransform,
                IsDragable      = false,
                IsToolBarItem   = true,
                IsSelected      = false,
                ContextMenuName = contextMenuName
            };

            var binding = new Binding
            {
                RelativeSource = new RelativeSource
                {
                    Mode         = RelativeSourceMode.FindAncestor,
                    AncestorType = typeof(DragGrip)
                },
                Path                = new PropertyPath("IsSelected"),
                Converter           = new BoolToIntConverter(),
                ConverterParameter  = "2.5",
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                Mode                = BindingMode.TwoWay
            };
            var border = new Border
            {
                Background  = backgound,
                Width       = width,
                Height      = 22,
                BorderBrush = Brushes.DeepSkyBlue,
                Child       =
                    new TextBlock
                {
                    Text                = text,
                    FontSize            = 16,
                    Foreground          = Brushes.White,
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Margin              = margin
                }
            };

            border.SetBinding(Border.BorderThicknessProperty, binding);
            newItem.Child       = border;
            newItem.ContextMenu = MainCanvas.FindResource(contextMenuName) as ContextMenu;

            return(newItem);
        }