父 WPF 之上的子 WPF (MvvmCross)

问题描述

我想在父窗口的顶部或至少在鼠标所在的位置打开一个新的 WPF 窗口。 我可以接收到正确的鼠标坐标,但它没有正确更新 Left 和 Top 属性,这意味着没有效果但是当我使用硬编码坐标时它可以工作

this.Left = System.Windows.Input.Mouse.GetPosition(null).X;
this.Top = System.Windows.Input.Mouse.GetPosition(null).Y;

所以我尝试在 WPF 中使用 WindowStartupLocation="CenterOwner",但我不知道如何在 MvvmCross 中设置父 WPF。 我通过父 viewmodel 这样调用子窗口:

ShowChildCommand = new MvxAsyncCommand(async () => await NavigationService.Navigate<Childviewmodel>());

但它不提供任何设置父级的选项。我的孩子 WPF 课程看起来像这样:

using MvvmCross.Platforms.Wpf.Presenters.Attributes;

namespace test.wpf.Views
{
    [MvxWindowPresentation(Identifier = nameof(ChildView),Modal = false)]
    public partial class GroupMembershipView
    {
        public ChildView()
        {
            InitializeComponent();
        }

    }

}

此外,我试图弄清楚如何在 WPF 本身中设置它:

Owner="{x:Static test.wpf:App.CurrentMainWindow}

但没有成功。 定义父级的正确方法是什么,或者只是在 MvvmCross 的顶部设置新的 WPF 窗口?

解决方法

我想我错过了以下帖子:How to set window's owner to MainWindow through XAML in WPF?

所以,我将提到的函数添加到我的 App.xaml.cs

public static MvxWindow CurrentMainWindow
{
    get { return (MvxWindow)Current.MainWindow; }
}

以及在帖子中提到的 WPF 中:

xmlns:test.wpf="clr-namespace:test.wpf"
WindowStartupLocation="CenterOwner" Owner="{x:Static test.wpf:App.CurrentMainWindow}"