繁体   English   中英

使内容对话框像 Groove 应用程序中的一样可移动

[英]make a content Dialog movable like the one in the Groove app

我创建了一个 ContentDialog 来应用样式(我不能用消息对话框和弹出窗口应用它),但是我遇到了问题,它不能移动,或者我不能像当我出现的框架一样关闭它点击 Groove App 中的“Connexion”按钮在此处输入图片说明

你有什么想法吗,我可以在ContentDialog 样式中修改哪一部分以使这个 ContentDialog 可移动并像顶部的图像一样关闭它

我在一个通用的应用程序上工作

你有什么想法吗,我可以在 ContentDialog 样式中修改哪一部分以使这个 ContentDialog 可移动并像顶部的图像一样关闭它。

恐怕ContentDialog是不可移动的,你在 Groove 应用程序或系统的邮件应用程序中显示的图像不是ContentDialog ,实际上,这个“对话框”是由UserDataAccountManager.ShowAddAccountAsync调用的。 如果我们使用 ProcessMonitor 来跟踪这个 UI,我们会发现这是一个系统应用 C:\\Windows\\SystemApps\\Microsoft.AccountsControl_cw5n1h2txyewy。 您可以在 SO: UWP Modal Window上的类似问题中看到图片和信息。

对于您的问题,我们无法启动 Microsoft.AccountsControl 之类的系统应用程序以获取结果,我们只能使用 API UserDataAccountManager.ShowAddAccountAsync调用它。 但是您可以创建一个 UWP 应用程序,并从另一个应用程序启动此应用程序以获取结果,为此,请参阅启动应用程序以获取结果

或者,如果您只想要一个可移动的 UI,您可以在您的应用程序中创建一个新窗口,并更改这个新窗口的大小,使其像ContentDialog一样弹出行为,但是这个新窗口将显示您应用程序的标题,而该标题不能是移除。

如何创建一个新窗口? 例如:

    private async void OnClick(object sender, RoutedEventArgs e)
    {
        var newCoreAppView = CoreApplication.CreateNewView();
        var appView = ApplicationView.GetForCurrentView();
        await newCoreAppView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, async () =>
        {
            var window = Window.Current;
            var newAppView = ApplicationView.GetForCurrentView();

            var frame = new Frame();
            window.Content = frame;

            frame.Navigate(typeof(BlankPage));            
            window.Activate();
            await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newAppView.Id, ViewSizePreference.Default, appView.Id, ViewSizePreference.Default);

        });
    }

以及如何更改新窗口的大小? 例如在新窗口中显示的页面的 cs 文件中:

public BlankPage()
        {
            this.InitializeComponent();
            this.Loaded += Page_Loaded;
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            var s = ApplicationView.GetForCurrentView();
            s.TryResizeView(new Size { Width = 600, Height = 320 });
        }

这将创建一个 600 宽和 320 高的窗口。

我认为你可以用另一种方式做到这一点:

  1. 创建一个 UserControl,像弹出窗口一样定义 UI。
  2. 将 ManipulationMode 设置为翻译。
  3. 处理 ManipulationDelta 事件来移动
  4. UserControll(让我们将 CompositeTransform 作为 RenderTransform)。
  5. 根据需要实现动画 在页面中使用 UserControll

这就是我的做法,因为我从 4 年到现在都没有找到任何答案:)

                            var dialog = new ContentDialog()
                            {
                                Title = "This is a Title!",
                                ManipulationMode = ManipulationModes.All,
                            };
                            dialog.ManipulationDelta += delegate (object sender, ManipulationDeltaRoutedEventArgs e)
                            {
                                if(!e.IsInertial)
                                    dialog.Margin = new Thickness(
                                        dialog.Margin.Left + e.Delta.Translation.X,
                                        dialog.Margin.Top + e.Delta.Translation.Y,
                                        dialog.Margin.Left - e.Delta.Translation.X,
                                        dialog.Margin.Top - e.Delta.Translation.Y
                                        );
                            };

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM