Example #1
0
        LayerFrame Generate(PositionedOverlaySettings Settings, string Text, Color BackgroundColor)
        {
            var control = new LayerFrame
            {
                Border =
                {
                    Background = new SolidColorBrush(BackgroundColor)
                },
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Label =
                {
                    Content    = Text,
                    Foreground = new SolidColorBrush(Colors.White)
                }
            };

            var vm = new PositionOverlayReactor(Settings);

            control.BindOne(HorizontalAlignmentProperty, vm.HAlignment);
            control.BindOne(VerticalAlignmentProperty, vm.VAlignment);
            control.BindOne(MarginProperty, vm.Margin);

            control.PositionUpdated += Rect =>
            {
                Settings.X = (int)Rect.X;
                Settings.Y = (int)Rect.Y;
            };

            return(control);
        }
Example #2
0
        LayerFrame Generate(PositionedOverlaySettings Settings, string Text, Color BackgroundColor)
        {
            var control = new LayerFrame
            {
                Border =
                {
                    Background = new SolidColorBrush(BackgroundColor)
                },
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Label =
                {
                    Content    = Text,
                    Foreground = new SolidColorBrush(Colors.White)
                }
            };

            void Update()
            {
                int left = 0, top = 0, right = 0, bottom = 0;

                switch (Settings.HorizontalAlignment)
                {
                case Alignment.Start:
                    control.HorizontalAlignment = HorizontalAlignment.Left;
                    left = Settings.X;
                    break;

                case Alignment.Center:
                    control.HorizontalAlignment = HorizontalAlignment.Center;
                    left = Settings.X;
                    break;

                case Alignment.End:
                    control.HorizontalAlignment = HorizontalAlignment.Right;
                    right = Settings.X;
                    break;
                }

                switch (Settings.VerticalAlignment)
                {
                case Alignment.Start:
                    control.VerticalAlignment = VerticalAlignment.Top;
                    top = Settings.Y;
                    break;

                case Alignment.Center:
                    control.VerticalAlignment = VerticalAlignment.Center;
                    top = Settings.Y;
                    break;

                case Alignment.End:
                    control.VerticalAlignment = VerticalAlignment.Bottom;
                    bottom = Settings.Y;
                    break;
                }

                Dispatcher.Invoke(() => control.Margin = new Thickness(left, top, right, bottom));
            }

            Settings.PropertyChanged += (S, E) => Update();

            Update();

            control.PositionUpdated += Rect =>
            {
                Settings.X = (int)Rect.X;
                Settings.Y = (int)Rect.Y;
            };

            return(control);
        }