Beispiel #1
0
 /// <summary>
 /// Löst das MessageReceived-Event aus.
 /// </summary>
 private void RaiseMessageReceivedEvent(System.Windows.HorizontalAlignment Allignment, string Message, string Sender, DateTime Date)
 {
     if (OnMessageReceived != null)
     {
         OnMessageReceived(this, Allignment, Message, Sender, Date);
     }
 }
Beispiel #2
0
 private void AddChat(object source, System.Windows.HorizontalAlignment Allignment, string Message, string Sender, DateTime Date)
 {
     stackPanelMessages.Children.Add(new ChatMessage()
     {
         HorizontalAlignment = Allignment,
         Message             = Message,
         From = Sender,
         Date = Date
     });
 }
Beispiel #3
0
        //
        // Alignment
        //
        public static Alignment ToXwtAlignment(SW.HorizontalAlignment alignment)
        {
            switch (alignment)
            {
            case SW.HorizontalAlignment.Left: return(Alignment.Start);

            case SW.HorizontalAlignment.Center: return(Alignment.Center);

            default: return(Alignment.End);
            }
        }
Beispiel #4
0
        private Grid createButton(string uid, System.Windows.VerticalAlignment v, System.Windows.HorizontalAlignment h, Color c)
        {
            var button = new Grid();

            button.Name                = uid;
            button.Uid                 = uid;
            button.Width               = 32;
            button.Height              = 32;
            button.VerticalAlignment   = v;
            button.HorizontalAlignment = h;
            button.Opacity             = 0.75;
            button.Background          = new SolidColorBrush(c);
            return(button);
        }
Beispiel #5
0
        public static TextAlignment ToEto(this sw.HorizontalAlignment align)
        {
            switch (align)
            {
            case sw.HorizontalAlignment.Left:
                return(TextAlignment.Left);

            case sw.HorizontalAlignment.Right:
                return(TextAlignment.Right);

            case sw.HorizontalAlignment.Center:
                return(TextAlignment.Center);

            default:
                throw new NotSupportedException();
            }
        }
        /// <summary>
        /// Get the right-hand edge of a child element.
        /// </summary>
        /// <param name="element">The child element.</param>
        /// <param name="leftEdge">The left edge of the current column.</param>
        /// <param name="width">The width allowed to the control.</param>
        /// <returns>The position of the right edge of the control.</returns>
        private double GetRight(FrameworkElement element, double leftEdge, double width)
        {
            double right = leftEdge + width;

            System.Windows.HorizontalAlignment alignment = element.HorizontalAlignment;
            Size size = element.DesiredSize;

            if (alignment == System.Windows.HorizontalAlignment.Left)
            {
                right -= width - size.Width;
            }
            else if (alignment == System.Windows.HorizontalAlignment.Center)
            {
                right -= (width - size.Width) / 2;
            }

            return(right);
        }
Beispiel #7
0
        public static Label CreateLabel <T>(T content, double width, double height, System.Windows.HorizontalAlignment horizontalContentAlignement, Brush textColor, double left, double top)
        {
            var label = new Label
            {
                Background = Brushes.Transparent,
                Content    = content,
                Width      = width,
                Height     = height,
                HorizontalContentAlignment = horizontalContentAlignement,
                VerticalContentAlignment   = VerticalAlignment.Center,
                Foreground = textColor
            };

            label.SetValue(Canvas.LeftProperty, left);
            label.SetValue(Canvas.TopProperty, top);

            return(label);
        }
        /// <summary>
        /// Create the border geometry.
        /// </summary>
        /// <param name="ha">The horizontal alignment.</param>
        /// <param name="va">The vertical alignment.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="margin">The margin.</param>
        /// <returns>The border geometry.</returns>
        private Geometry CreateBorderGeometry(
            System.Windows.HorizontalAlignment ha, System.Windows.VerticalAlignment va, double width, double height, out Thickness margin)
        {
            double m    = this.Distance;
            var    rect = new Rect(
                ha == System.Windows.HorizontalAlignment.Left ? m : 0, va == System.Windows.VerticalAlignment.Top ? m : 0, width, height);

            margin = new Thickness
            {
                Left   = ha == System.Windows.HorizontalAlignment.Left ? m : 0,
                Top    = va == System.Windows.VerticalAlignment.Top ? m : 0,
                Right  = ha == System.Windows.HorizontalAlignment.Right ? m : 0,
                Bottom = va == System.Windows.VerticalAlignment.Bottom ? m : 0
            };
            return(new RectangleGeometry {
                Rect = rect                            /*, RadiusX = this.CornerRadius, RadiusY = this.CornerRadius*/
            });
        }
Beispiel #9
0
        private TextAlignment ConvertAlignment(System.Windows.HorizontalAlignment horizontalAlignment)
        {
            switch (horizontalAlignment)
            {
            case System.Windows.HorizontalAlignment.Center:
                return(TextAlignment.Center);

            case System.Windows.HorizontalAlignment.Right:
                return(TextAlignment.Right);

            case System.Windows.HorizontalAlignment.Stretch:
                return(TextAlignment.Justify);

            case System.Windows.HorizontalAlignment.Left:
            default:
                return(TextAlignment.Left);
            }
        }
Beispiel #10
0
        public virtual HorizontalAlignment Parse(System.Windows.HorizontalAlignment horizontalAlignment)
        {
            switch (horizontalAlignment)
            {
            case System.Windows.HorizontalAlignment.Left:
                return(HorizontalAlignment.Left);

            case System.Windows.HorizontalAlignment.Center:
                return(HorizontalAlignment.Center);

            case System.Windows.HorizontalAlignment.Right:
                return(HorizontalAlignment.Right);

            case System.Windows.HorizontalAlignment.Stretch:
                return(HorizontalAlignment.Fill);
            }

            throw new ArgumentOutOfRangeException("horizontalAlignment");
        }
        private System.Windows.Controls.Button ImageButtonHelper(double imageHeight, double imageWidth, string imageName,
                                                                 System.Windows.HorizontalAlignment horizontalAlignment, System.Windows.VerticalAlignment verticalAlignment)
        {
            System.Windows.Controls.Button button = new System.Windows.Controls.Button();
            button.Height = imageHeight;
            button.Width  = imageWidth;
            button.HorizontalAlignment = horizontalAlignment;
            button.VerticalAlignment   = verticalAlignment;

            try
            {
                button.Content = ImageHelper(imageName);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(button);
        }
 private static TFrameworkElement HorizontalAlignment <TFrameworkElement>(this TFrameworkElement @this, H horizontalAlignment)
     where TFrameworkElement : FrameworkElement
 {
     @this.HorizontalAlignment = horizontalAlignment;
     return(@this);
 }
        /// <summary>
        /// Creates a border geometry with a 'pointer'.
        /// </summary>
        /// <param name="ha">The horizontal alignment.</param>
        /// <param name="va">The vertical alignment.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="margin">The margin.</param>
        /// <returns>The border geometry.</returns>
        private Geometry CreatePointerBorderGeometry(
            System.Windows.HorizontalAlignment ha, System.Windows.VerticalAlignment va, double width, double height, out Thickness margin)
        {
            Point[] points = null;
            double  m      = this.Distance;

            margin = new Thickness();

            if (ha == System.Windows.HorizontalAlignment.Center && va == System.Windows.VerticalAlignment.Bottom)
            {
                double x0 = 0;
                double x1 = width;
                double x2 = (x0 + x1) / 2;
                double y0 = 0;
                double y1 = height;
                margin = new Thickness {
                    Bottom = m
                };
                points = new[]
                {
                    new Point(x0, y0), new Point(x1, y0), new Point(x1, y1), new Point(x2 + (m / 2), y1),
                    new Point(x2, y1 + m), new Point(x2 - (m / 2), y1), new Point(x0, y1)
                };
            }

            if (ha == System.Windows.HorizontalAlignment.Center && va == System.Windows.VerticalAlignment.Top)
            {
                double x0 = 0;
                double x1 = width;
                double x2 = (x0 + x1) / 2;
                double y0 = m;
                double y1 = m + height;
                margin = new Thickness {
                    Top = m
                };
                points = new[]
                {
                    new Point(x0, y0), new Point(x2 - (m / 2), y0), new Point(x2, 0), new Point(x2 + (m / 2), y0),
                    new Point(x1, y0), new Point(x1, y1), new Point(x0, y1)
                };
            }

            if (ha == System.Windows.HorizontalAlignment.Left && va == System.Windows.VerticalAlignment.Center)
            {
                double x0 = m;
                double x1 = m + width;
                double y0 = 0;
                double y1 = height;
                double y2 = (y0 + y1) / 2;
                margin = new Thickness {
                    Left = m
                };
                points = new[]
                {
                    new Point(0, y2), new Point(x0, y2 - (m / 2)), new Point(x0, y0), new Point(x1, y0),
                    new Point(x1, y1), new Point(x0, y1), new Point(x0, y2 + (m / 2))
                };
            }

            if (ha == System.Windows.HorizontalAlignment.Right && va == System.Windows.VerticalAlignment.Center)
            {
                double x0 = 0;
                double x1 = width;
                double y0 = 0;
                double y1 = height;
                double y2 = (y0 + y1) / 2;
                margin = new Thickness {
                    Right = m
                };
                points = new[]
                {
                    new Point(x1 + m, y2), new Point(x1, y2 + (m / 2)), new Point(x1, y1), new Point(x0, y1),
                    new Point(x0, y0), new Point(x1, y0), new Point(x1, y2 - (m / 2))
                };
            }

            if (ha == System.Windows.HorizontalAlignment.Left && va == System.Windows.VerticalAlignment.Top)
            {
                m *= 0.67;
                double x0 = m;
                double x1 = m + width;
                double y0 = m;
                double y1 = m + height;
                margin = new Thickness {
                    Left = m, Top = m
                };
                points = new[]
                {
                    new Point(0, 0), new Point(m * 2, y0), new Point(x1, y0), new Point(x1, y1), new Point(x0, y1),
                    new Point(x0, m * 2)
                };
            }

            if (ha == System.Windows.HorizontalAlignment.Right && va == System.Windows.VerticalAlignment.Top)
            {
                m *= 0.67;
                double x0 = 0;
                double x1 = width;
                double y0 = m;
                double y1 = m + height;
                margin = new Thickness {
                    Top = m, Right = m
                };
                points = new[]
                {
                    new Point(x1 + m, 0), new Point(x1, y0 + m), new Point(x1, y1), new Point(x0, y1),
                    new Point(x0, y0), new Point(x1 - m, y0)
                };
            }

            if (ha == System.Windows.HorizontalAlignment.Left && va == System.Windows.VerticalAlignment.Bottom)
            {
                m *= 0.67;
                double x0 = m;
                double x1 = m + width;
                double y0 = 0;
                double y1 = height;
                margin = new Thickness {
                    Left = m, Bottom = m
                };
                points = new[]
                {
                    new Point(0, y1 + m), new Point(x0, y1 - m), new Point(x0, y0), new Point(x1, y0),
                    new Point(x1, y1), new Point(x0 + m, y1)
                };
            }

            if (ha == System.Windows.HorizontalAlignment.Right && va == System.Windows.VerticalAlignment.Bottom)
            {
                m *= 0.67;
                double x0 = 0;
                double x1 = width;
                double y0 = 0;
                double y1 = height;
                margin = new Thickness {
                    Right = m, Bottom = m
                };
                points = new[]
                {
                    new Point(x1 + m, y1 + m), new Point(x1 - m, y1), new Point(x0, y1), new Point(x0, y0),
                    new Point(x1, y0), new Point(x1, y1 - m)
                };
            }

            if (points == null)
            {
                return(null);
            }

            var pointCollection = new PointCollection();

            foreach (var point in points)
            {
                pointCollection.Add(point);
            }

            var segments = new PathSegmentCollection {
                new PolyLineSegment {
                    Points = pointCollection
                }
            };
            var pf = new PathFigure {
                StartPoint = points[0], Segments = segments, IsClosed = true
            };

            return(new PathGeometry {
                Figures = new PathFigureCollection {
                    pf
                }
            });
        }
 public static void SetDockHorizontal(DependencyObject obj, HorizontalAlignment value)
 {
     obj.SetValue(DockHorizontalProperty, value);
 }
Beispiel #15
0
        private void createSensors()
        {
            if (ext.distanceSensors == null)
            {
                ext.distanceSensors = new List <DistanceSensor>();
            }
            else
            {
                ext.distanceSensors.Clear();
            }
            List <DistanceSensor> distanceSensors = ext.distanceSensors;
            DistanceSensor        distanceSensor  = new DistanceSensor()
            {
                Name  = "FrontRight",
                Angle = 45,
                Min   = 100,
                Max   = 800
            };

            distanceSensors.Add(distanceSensor);
            List <DistanceSensor> distanceSensors1 = ext.distanceSensors;
            DistanceSensor        distanceSensor1  = new DistanceSensor()
            {
                Name  = "FrontLeft",
                Angle = -45,
                Min   = 100,
                Max   = 800
            };

            distanceSensors1.Add(distanceSensor1);
            List <DistanceSensor> distanceSensors2 = ext.distanceSensors;
            DistanceSensor        distanceSensor2  = new DistanceSensor()
            {
                Name  = "SideRight",
                Angle = 90,
                Min   = 40,
                Max   = 400
            };

            distanceSensors2.Add(distanceSensor2);
            List <DistanceSensor> distanceSensors3 = ext.distanceSensors;
            DistanceSensor        distanceSensor3  = new DistanceSensor()
            {
                Name  = "SideLeft",
                Angle = -90,
                Min   = 40,
                Max   = 400
            };

            distanceSensors3.Add(distanceSensor3);
            foreach (DistanceSensor distanceSensor4 in ext.distanceSensors)
            {
                Ellipse ellipse  = new Ellipse();
                Ellipse ellipse1 = new Ellipse();
                double  num      = 8;
                double  num1     = num;
                ellipse1.Height = num;
                double num2 = num1;
                num1           = num2;
                ellipse1.Width = num2;
                double num3 = num1;
                num1           = num3;
                ellipse.Height = num3;
                ellipse.Width  = num1;
                int num4 = 0;
                System.Windows.HorizontalAlignment horizontalAlignment = (System.Windows.HorizontalAlignment)num4;
                ellipse.HorizontalAlignment  = (System.Windows.HorizontalAlignment)num4;
                ellipse1.HorizontalAlignment = horizontalAlignment;
                int num5 = 0;
                System.Windows.VerticalAlignment verticalAlignment = (System.Windows.VerticalAlignment)num5;
                ellipse.VerticalAlignment  = (System.Windows.VerticalAlignment)num5;
                ellipse1.VerticalAlignment = verticalAlignment;
                SolidColorBrush black = Brushes.Black;
                Brush           brush = black;
                ellipse.Stroke  = black;
                ellipse1.Stroke = brush;
                SolidColorBrush yellow = Brushes.Yellow;
                brush         = yellow;
                ellipse.Fill  = yellow;
                ellipse1.Fill = brush;
                double num6 = 1;
                num1 = num6;
                ellipse.StrokeThickness  = num6;
                ellipse1.StrokeThickness = num1;
                Line line = new Line()
                {
                    StrokeThickness = 3,
                    Stroke          = Brushes.Blue
                };
                distanceSensor4.setControls(ellipse, ellipse1, line);
                this.bigGrid.Children.Add(line);
                this.bigGrid.Children.Add(ellipse);
                this.bigGrid.Children.Add(ellipse1);
                Panel.SetZIndex(line, 10);
                Panel.SetZIndex(ellipse, 11);
                Panel.SetZIndex(ellipse1, 11);
            }
        }
 public static void SetDockHorizontal(DependencyObject obj, HorizontalAlignment value)
 {
     obj.SetValue(DockHorizontalProperty, value);
 }
Beispiel #17
0
        public Anchor(Node node, string name, System.Windows.VerticalAlignment vertical, System.Windows.HorizontalAlignment horizontal, System.Windows.Thickness margin)
        {
            this.node = node;

            this.Name                = name;
            this.Background          = Brushes.Transparent;
            this.VerticalAlignment   = vertical;
            this.HorizontalAlignment = horizontal;
            this.Margin              = margin;
            this.Width               = 16;
            this.Height              = 16;

            //listeners

            Viewbox vb = new Viewbox();

            vb.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            vb.VerticalAlignment   = System.Windows.VerticalAlignment.Stretch;
            vb.Stretch             = Stretch.Fill;
            vb.Margin = new System.Windows.Thickness(3);

            Grid ingrid = new Grid();

            l1                 = new Line();
            l1.X1              = 0;
            l1.Y1              = 0;
            l1.X2              = 100;
            l1.Y2              = 100;
            l1.Stroke          = Brushes.Transparent;
            l1.StrokeThickness = 8;

            l2                 = new Line();
            l2.X1              = 0;
            l2.Y1              = 100;
            l2.X2              = 100;
            l2.Y2              = 0;
            l2.Stroke          = Brushes.Transparent;
            l2.StrokeThickness = 8;

            ingrid.Children.Add(l1);
            ingrid.Children.Add(l2);
            vb.Child = ingrid;
            this.Children.Add(vb);

            ContextMenu cm1   = new ContextMenu();
            MenuItem    item1 = new MenuItem();

            item1.Header = "Add Child";
            item1.Click += Anchor_OnAddChildClick;
            cm1.Items.Add(item1);
            this.ContextMenu = cm1;

            this.MouseEnter           += Anchor_MouseEnter;
            this.MouseLeave           += Anchor_MouseLeave;
            this.MouseRightButtonDown += Anchor_MouseRightButtonDown;
            this.MouseLeftButtonDown  += Anchor_MouseLeftButtonDown;
            //this.LayoutUpdated += Anchor_LayoutUpdated;

            this.AllowDrop = true;
            this.Drop     += Anchor_Drop;
        }
Beispiel #18
0
        private static CustomPopupPlacementCallback CreatePlacementCallback(Popup popup)
        {
            return(delegate(Size popupSize, Size targetSize, Point offset)
            {
                int dockedScreenIndex = GetDockedScreen(popup);
                if (dockedScreenIndex < 0)
                {
                    return new CustomPopupPlacement[0];
                }

                Screen dockedScreen;
                if (dockedScreenIndex < Screen.AllScreens.Length)
                {
                    dockedScreen = Screen.AllScreens[dockedScreenIndex];
                }
                else
                {
                    dockedScreen = Screen.PrimaryScreen;
                }

                var workingArea = dockedScreen.WorkingArea;

                var popupWidth = popupSize.Width;
                var popupHeight = popupSize.Height;

                var areaLeft = workingArea.Left;
                var areaTop = workingArea.Top;
                var areaWidth = workingArea.Width;
                var areaHeight = workingArea.Height;

                var popupLeft = 0.0;
                var popupTop = 0.0;

                HorizontalAlignment horizontal = GetDockHorizontal(popup);
                VerticalAlignment vertical = GetDockVertical(popup);

                switch (horizontal)
                {
                case HorizontalAlignment.Left:
                    popupLeft = areaLeft;
                    break;

                case HorizontalAlignment.Center:
                    popupLeft = areaLeft + (areaWidth / 2 - popupWidth / 2);
                    break;

                case HorizontalAlignment.Right:
                    popupLeft = areaLeft + areaWidth - popupWidth;
                    break;

                case HorizontalAlignment.Stretch:
                    popupLeft = areaLeft;
                    popupWidth = areaWidth;
                    break;
                }

                switch (vertical)
                {
                case VerticalAlignment.Top:
                    popupTop = areaTop;
                    break;

                case VerticalAlignment.Center:
                    popupTop = areaTop + (areaHeight / 2 - popupHeight / 2);
                    break;

                case VerticalAlignment.Bottom:
                    popupTop = areaTop + areaHeight - popupHeight;
                    break;

                case VerticalAlignment.Stretch:
                    popupTop = areaTop;
                    popupHeight = areaHeight;
                    break;
                }
                if ((popupTop < areaTop) || (popupTop + popupHeight > areaTop + areaHeight))
                {
                    popupTop = areaTop;
                    popupHeight = areaHeight;
                }
                if ((popupLeft < areaLeft) || (popupLeft + popupWidth > areaLeft + areaWidth))
                {
                    popupLeft = areaLeft;
                    popupWidth = areaWidth;
                }
                var popupLocation = new Point(popupLeft, popupTop);
                if (horizontal == HorizontalAlignment.Stretch)
                {
                    popup.Width = areaWidth;
                }
                if (vertical == VerticalAlignment.Stretch)
                {
                    popup.Height = areaHeight;
                }

                var popupPlacement = new CustomPopupPlacement(popupLocation, PopupPrimaryAxis.Horizontal);
                return new[]
                {
                    popupPlacement
                };
            });
        }
Beispiel #19
0
        public static Grid GetHotkeyListAsButtonGrid(List <string> hotkeys, Style buttonStyle = null, double?spacing = null, System.Windows.HorizontalAlignment horizontalAlignment = System.Windows.HorizontalAlignment.Center)
        {
            int currentIndex = 0;
            var buttonGrid   = new Grid();

            buttonGrid.HorizontalAlignment = horizontalAlignment;

            var rowDefinition = new RowDefinition();

            rowDefinition.Height = GridLength.Auto;
            buttonGrid.RowDefinitions.Add(rowDefinition);

            for (int i = 0; i < hotkeys.Count; i++)
            {
                var columnDefinition = new ColumnDefinition();
                columnDefinition.Width = GridLength.Auto;
                buttonGrid.ColumnDefinitions.Add(columnDefinition);

                if (spacing.HasValue && (i != hotkeys.Count - 1))
                {
                    var spacingDefinition = new ColumnDefinition();
                    spacingDefinition.Width = new GridLength(spacing.Value);
                    buttonGrid.ColumnDefinitions.Add(spacingDefinition);
                }
            }

            // if we have spacing enabled, indices after 0 will have to be multiplied two
            // before spacing: 0 1 2 3 4 (button indices)
            // after spacing: 0 s 1 s 2 s 3 s 4
            // after spacing: 0 s 2 s 4 s 6 s 8
            foreach (var hotkeyName in hotkeys)
            {
                var tempButton = new System.Windows.Controls.Button();
                if (buttonStyle != null)
                {
                    tempButton.Style = buttonStyle;
                }

                tempButton.Content = hotkeyName;
                buttonGrid.InsertAt(tempButton, spacing.HasValue ? currentIndex * 2 : currentIndex, 0);
                currentIndex++;
            }

            return(buttonGrid);
        }
        public static void RelocateWindow(Window window)
        {
            int dockedScreenIndex = GetDockedScreen(window);

            if (dockedScreenIndex < 0)
            {
                return;
            }

            Screen dockedScreen;

            if (dockedScreenIndex < Screen.AllScreens.Length)
            {
                dockedScreen = Screen.AllScreens[dockedScreenIndex];
            }
            else
            {
                dockedScreen = Screen.PrimaryScreen;
            }

            var workingArea = dockedScreen.WorkingArea;

            var windowWidth  = window.Width;
            var windowHeight = window.Height;

            var areaLeft   = workingArea.Left;
            var areaTop    = workingArea.Top;
            var areaWidth  = workingArea.Width;
            var areaHeight = workingArea.Height;

            var windowLeft = 0.0;
            var windowTop  = 0.0;

            HorizontalAlignment horizontal = GetDockHorizontal(window);
            VerticalAlignment   vertical   = GetDockVertical(window);

            switch (horizontal)
            {
            case HorizontalAlignment.Left:
                windowLeft = areaLeft;
                break;

            case HorizontalAlignment.Center:
                windowLeft = areaLeft + (areaWidth / 2 - windowWidth / 2);
                break;

            case HorizontalAlignment.Right:
                windowLeft = areaLeft + areaWidth - windowWidth;
                break;

            case HorizontalAlignment.Stretch:
                windowLeft  = areaLeft;
                windowWidth = areaWidth;
                break;
            }

            switch (vertical)
            {
            case VerticalAlignment.Top:
                windowTop = areaTop;
                break;

            case VerticalAlignment.Center:
                windowTop = areaTop + (areaHeight / 2 - windowHeight / 2);
                break;

            case VerticalAlignment.Bottom:
                windowTop = areaTop + areaHeight - windowHeight;
                break;

            case VerticalAlignment.Stretch:
                windowTop    = areaTop;
                windowHeight = areaHeight;
                break;
            }
            if ((windowTop < areaTop) || (windowTop + windowHeight > areaTop + areaHeight))
            {
                windowTop    = areaTop;
                windowHeight = areaHeight;
            }
            if ((windowLeft < areaLeft) || (windowLeft + windowWidth > areaLeft + areaWidth))
            {
                windowLeft  = areaLeft;
                windowWidth = areaWidth;
            }
            var popupLocation = new Point(windowLeft, windowTop);

            if (horizontal == HorizontalAlignment.Stretch)
            {
                window.Width = areaWidth;
            }
            if (vertical == VerticalAlignment.Stretch)
            {
                window.Height = areaHeight;
            }
            window.Left   = windowLeft;
            window.Height = windowHeight;
        }
Beispiel #21
0
        public static StackPanel GetHotkeyListAsButtonGrid(List <string> hotkeys, Style buttonStyle = null, Style labelStyle = null, double?spacing = null, System.Windows.HorizontalAlignment horizontalAlignment = System.Windows.HorizontalAlignment.Center, System.Windows.VerticalAlignment verticalAlignment = System.Windows.VerticalAlignment.Center)
        {
            var stackPanel = new StackPanel();

            stackPanel.Orientation = Orientation.Horizontal;

            for (int i = 0; i < hotkeys.Count; i++)
            {
                var tempButton = new System.Windows.Controls.Button();
                tempButton.HorizontalAlignment = horizontalAlignment;
                tempButton.VerticalAlignment   = verticalAlignment;
                if (buttonStyle != null)
                {
                    tempButton.Style = buttonStyle;
                }

                tempButton.Content = hotkeys[i];

                stackPanel.Children.Add(tempButton);

                if (i != (hotkeys.Count - 1))
                {
                    // insert separator only if this is not the only (or the last) element
                    var label = new Label();
                    label.HorizontalAlignment = horizontalAlignment;
                    label.VerticalAlignment   = verticalAlignment;
                    label.Padding             = new System.Windows.Thickness(spacing ?? 1d);
                    label.Content             = "+";
                    if (labelStyle != null)
                    {
                        label.Style = labelStyle;
                    }

                    stackPanel.Children.Add(label);
                }
            }

            return(stackPanel);
        }