Beispiel #1
0
        public DragGrip Clone()
        {
            var newItem = new DragGrip
            {
                Name            = "Cloned" + Guid.NewGuid().ToString().Replace("-", ""),
                RenderTransform =
                    new TranslateTransform(((TranslateTransform)RenderTransform).X,
                                           ((TranslateTransform)RenderTransform).Y),
                InitialPoint    = InitialPoint,
                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  = ((Border)Child).Background,
                Width       = ActualWidth,
                Height      = ActualHeight,
                BorderBrush = Brushes.DeepSkyBlue,
                Child       = new TextBlock
                {
                    Text                = ((TextBlock)((Border)Child).Child).Text,
                    FontSize            = 16,
                    Foreground          = Brushes.White,
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Margin              = ((TextBlock)((Border)Child).Child).Margin
                }
            };

            border.SetBinding(Border.BorderThicknessProperty, binding);
            newItem.ContextMenu = (ContextMenu)((Canvas)Parent).FindResource(ContextMenuName);
            newItem.Child       = border;
            return(newItem);
        }
        public DragGrip Clone()
        {
            var newItem = new DragGrip
            {
                Name = "Cloned" + Guid.NewGuid().ToString().Replace("-", ""),
                RenderTransform =
                    new TranslateTransform(((TranslateTransform) RenderTransform).X,
                        ((TranslateTransform) RenderTransform).Y),
                InitialPoint = InitialPoint,
                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 = ((Border) Child).Background,
                Width = ActualWidth,
                Height = ActualHeight,
                BorderBrush = Brushes.DeepSkyBlue,
                Child = new TextBlock
                {
                    Text = ((TextBlock) ((Border) Child).Child).Text,
                    FontSize = 16,
                    Foreground = Brushes.White,
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Margin = ((TextBlock) ((Border) Child).Child).Margin
                }
            };

            border.SetBinding(Border.BorderThicknessProperty, binding);
            newItem.ContextMenu = (ContextMenu)((Canvas)Parent).FindResource(ContextMenuName);
            newItem.Child = border;
            return newItem;
        }