简体   繁体   English

WinUI3 Window -> 显示对话框

[英]WinUI3 Window -> ShowDialog

I am trying to show the window as ShowDialog (same as WPF) in the WinUI3, but found that the currenly present method window.Activate() does not behave the same as ShowDialog().我试图在 WinUI3 中将 window 显示为 ShowDialog(与 WPF 相同),但发现当前存在的方法 window.Activate() 的行为与 ShowDialog() 不同。

1.) Is there any way to acheieve this in WinUI3, to show window as ShowDialog() (as in WPF). 1.) 有什么方法可以在 WinUI3 中实现这一点,将 window 显示为 ShowDialog()(如在 WPF 中)。

2.) I tried to use the ContentDialog, but the limitation is that, I can only one dialog at a time. 2.) 我尝试使用 ContentDialog,但限制是我一次只能使用一个对话框。 Suppose, A content dialog contains various input fields or other controls, Now If I want to pop up a messagedialog on top of that, I cannot acheive this, because a ContentDialog is already open.假设,一个内容对话框包含各种输入字段或其他控件,现在如果我想在其上弹出一个消息对话框,我无法实现这一点,因为 ContentDialog 已经打开。

Is there any way to show a MessageDialog in buttonclick event of ContentDialog.有什么方法可以在 ContentDialog 的 buttonclick 事件中显示 MessageDialog。

There's an issue regarding to this.有一个关于这个的问题 So for the moment, you can't create nested ContentDialogs .所以目前,您不能创建嵌套的ContentDialogs

As a workaround (for the moment), you can use the TeachingTip like this.作为解决方法(目前),您可以像这样使用TeachingTip Should be enough to show messages.应该足以显示消息。

MainPage.xaml主页.xaml

<Page
    x:Class="ContentDialogTests.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="using:ContentDialogTests"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
    mc:Ignorable="d">
    <Grid>
        <Button
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Click="ShowContentDialogButton_Click"
            Content="Show parent dialog" />
        <ContentDialog
            x:Name="ContentDialogControl"
            Title="ContentDialog"
            CloseButtonText="Close">
            <Button
                Click="ShowTeachingTipButton_Click"
                Content="Show teaching tip" />
        </ContentDialog>
        <TeachingTip
            x:Name="TeachingTipControl"
            Content="Teaching tip"
            IsOpen="False"
            PreferredPlacement="Center" />
    </Grid>
</Page>

MainPage.xaml.cs MainPage.xaml.cs

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System;

namespace ContentDialogTests;

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
        this.Loaded += MainPage_Loaded;
    }

    private void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        this.TeachingTipControl.Closed += (sender, args) => this.ContentDialogControl.IsEnabled = true;
    }

    private async void ShowContentDialogButton_Click(object sender, RoutedEventArgs e)
    {
        _ = await ContentDialogControl.ShowAsync();
    }

    private void ShowTeachingTipButton_Click(object sender, RoutedEventArgs e)
    {
        this.ContentDialogControl.IsEnabled = false;
        this.TeachingTipControl.IsOpen = true;
    }
}

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

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