benruehl / adonis-ui

Lightweight UI toolkit for WPF applications offering classic but enhanced windows visuals
https://benruehl.github.io/adonis-ui/
MIT License
1.69k stars 143 forks source link

center window don't work #188

Open PepiBobanov opened 2 years ago

PepiBobanov commented 2 years ago

Create new AdonisWindow with SizeToContent="WidthAndHeight" and WindowStartupLocation="CenterOwner"

Owner = parent ShowDialog()

window is not centered :(

PepiBobanov commented 2 years ago

It become Help yourself thing :) window.SizeChanged += (s, e) => CenterOwner(window);

    private void CenterOwner( Window w)
    {
        if (w.Owner != null)
        {
            double top = w.Owner.Top + ((w.Owner.Height - w.ActualHeight) / 2);
            double left = w.Owner.Left + ((w.Owner.Width - w.ActualWidth) / 2);

            w.Top = top < 0 ? 0 : top;
            w.Left = left < 0 ? 0 : left;
        }
    }