// Note that this can be called if e.g. the Layouter's AnchoringRect changes protected override void OnLayouterResultChanged(PropertyChangedEventArgs <LayoutResult> args) { var dpiResolution = DpiResolutions.FromAvalonElement(window); var location = args.New.Bounds.ToAvalonRect(dpiResolution); window.Top = location.Top; window.Left = location.Left; }
public override IPopupLayouter CreateLayouter(Lifetime lifetime) { var anchor = WindowAnchoringRect.AnchorToPrimaryMainWindowSafe(lifetime, mainWindow, windowsHookManager); var dispositions = new[] { new Anchoring2D(Anchoring.MiddleWithin, Anchoring.FarWithin) }; // Padding is in pixels... unsafe { var dpi = DpiResolutions.FromHWnd((void *)mainWindow.GetPrimaryWindow().Handle); var padding = 75.0 / DpiResolution.DeviceIndependent96DpiValue * dpi.DpiY; return(new DockingLayouter(lifetime, anchor, dispositions, (int)padding)); } }
// Use the desired size to calculate a new layout // Called from: // * ctor (although unlikely to be valid) // * OnSourceInitialized // * Before show // * On size changed private void UpdatePopupLayout() { if (!window.IsMeasureValid) { window.Measure(new Size(double.MaxValue, double.MaxValue)); } if (window.IsMeasureValid) { // Setting this causes the Layouter to compute a new LayoutResult and // we get notified via OnLayouterResultChanged var dpiResolution = DpiResolutions.FromAvalonElement(window); Layouter.Size.Value = window.DesiredSize.ToWinFormsSize(dpiResolution); // TODO: Should we check to see if the layouter gives us a different size, then re-measure? } }