public PositionOverlayReactor(PositionedOverlaySettings Settings) { HAlignment = Settings .ObserveProperty(M => M.HorizontalAlignment) .Select(M => { switch (M) { case Alignment.Start: return(HorizontalAlignment.Left); case Alignment.Center: return(HorizontalAlignment.Center); case Alignment.End: return(HorizontalAlignment.Right); default: return(HorizontalAlignment.Stretch); } }) .ToReadOnlyReactivePropertySlim(); VAlignment = Settings .ObserveProperty(M => M.VerticalAlignment) .Select(M => { switch (M) { case Alignment.Start: return(VerticalAlignment.Top); case Alignment.Center: return(VerticalAlignment.Center); case Alignment.End: return(VerticalAlignment.Bottom); default: return(VerticalAlignment.Stretch); } }) .ToReadOnlyReactivePropertySlim(); Margin = Settings .ObserveProperty(M => M.HorizontalAlignment) .CombineLatest( Settings .ObserveProperty(M => M.VerticalAlignment), Settings .ObserveProperty(M => M.X), Settings .ObserveProperty(M => M.Y), MarginPropSelector) .ToReadOnlyReactivePropertySlim(); }
private Controls.LayerFrame Generate(PositionedOverlaySettings settings, string text, Color backgroundColor) { var control = new Controls.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); }