Exemple #1
0
        public ElementAdorner(UIElement adornedElement, IControlBox controlBox)
            : base(adornedElement)
        {
            visualChildren = new VisualCollection(this);

            FrameworkElement box = controlBox as FrameworkElement;
            this.controlBox = box;
            panel.Children.Add(box);
            panel.Orientation = Orientation.Vertical;
            visualChildren.Add(panel);

            // Call a helper method to initialize the Thumbs
            // with a customized cursors.
            BuildAdornerCorner(ref resizeThumb, Cursors.SizeNWSE);

            // Add handlers for resizing.

            resizeThumb.DragDelta += new DragDeltaEventHandler(HandleBottomRight);
            this.ProcessControlBox(controlBox);
            this.MouseEnter += new MouseEventHandler(adornedElement_MouseEnter);
            this.MouseLeave += new MouseEventHandler(adornedElement_MouseLeave);
            this.AdornedElement.MouseEnter += new MouseEventHandler(adornedElement_MouseEnter);
            this.AdornedElement.MouseLeave += new MouseEventHandler(adornedElement_MouseLeave);
            this.Opacity = 0;
        }
Exemple #2
0
        private void ProcessControlBox(IControlBox controlBox)
        {
            Binding dragBind = new Binding("AllowDrag");
            dragBind.Source = this.AdornedElement;
            controlBox.DragThumb.MouseLeftButtonDown += new MouseButtonEventHandler(DragThumb_MouseLeftButtonDown);
            controlBox.DragThumb.DragDelta += new DragDeltaEventHandler(DragDeltaEvent);
            controlBox.DragThumb.DragStarted += new DragStartedEventHandler(drag_DragStarted);
            controlBox.DragThumb.DragCompleted += new DragCompletedEventHandler(drag_DragCompleted);
            controlBox.MaximizeButton.Checked += new RoutedEventHandler(OnMaximizeButtonChecked);
            controlBox.MinimizeButton.Click += new RoutedEventHandler(OnMinimizeButtonClick);
            controlBox.CloseButton.Click += new RoutedEventHandler(OnCloseButtonClick);
            ControlBoxStatesConverter converter = new ControlBoxStatesConverter();
            BoolToVisibilityConverter boolVisConverter = new BoolToVisibilityConverter();

            Binding minimzeBinding = new Binding("SupportedVisualStates");
            minimzeBinding.Converter = converter;
            minimzeBinding.ConverterParameter = 1;
            minimzeBinding.Source = this.AdornedElement;
            minimzeBinding.Mode = BindingMode.TwoWay;
            controlBox.MinimizeButton.SetBinding(UIElement.VisibilityProperty, minimzeBinding);

            Binding maximizeBinding = new Binding("SupportedVisualStates");
            maximizeBinding.Converter = converter;
            maximizeBinding.ConverterParameter = 2;
            maximizeBinding.Source = this.AdornedElement;
            maximizeBinding.Mode = BindingMode.TwoWay;
            controlBox.MaximizeButton.SetBinding(UIElement.VisibilityProperty, minimzeBinding);

            Binding closeBinding = new Binding("SupportedVisualStates");
            closeBinding.Converter = converter;
            closeBinding.ConverterParameter = 3;
            closeBinding.Source = this.AdornedElement;
            closeBinding.Mode = BindingMode.TwoWay;
            controlBox.CloseButton.SetBinding(UIElement.VisibilityProperty, closeBinding);

            Binding allowDragBinding = new Binding("AllowDrag");
            allowDragBinding.Converter = boolVisConverter;
            allowDragBinding.Source = this.AdornedElement;
            allowDragBinding.Mode = BindingMode.TwoWay;
            controlBox.DragThumb.SetBinding(UIElement.VisibilityProperty, allowDragBinding);

            Binding allowPinBinding = new Binding("AllowSendToBackground");
            allowPinBinding.Converter = boolVisConverter;
            allowPinBinding.Source = this.AdornedElement;
            allowPinBinding.Mode = BindingMode.TwoWay;
            controlBox.SendToBackgroundButton.SetBinding(UIElement.VisibilityProperty, allowPinBinding);

            Binding isPinnnedBinding = new Binding("IsBackground");
            isPinnnedBinding.Source = this.AdornedElement;
            isPinnnedBinding.Mode = BindingMode.TwoWay;
            controlBox.SendToBackgroundButton.SetBinding(ToggleButton.IsCheckedProperty, isPinnnedBinding);

            Binding allowResizing = new Binding("AllowResize");
            allowResizing.Converter = boolVisConverter;
            allowResizing.Source = this.AdornedElement;
            allowResizing.Mode = BindingMode.TwoWay;
            resizeThumb.SetBinding(UIElement.VisibilityProperty, allowResizing);
        }