MahApps - SimpleChildWindow

MahApps - SimpleChildWindow

我正在尝试从 MahApps 包

中设置一个 SimpleChildWindow

不幸的是,我无法理解示例并有几个问题:

  1. 它说:

Directly in XAML

在 parent 的 window 中还是单独的 window?

  1. await this.ShowChildWindowAsync(new CoolChildWindow() { IsModal = false });
    • 我们从哪里得到 CoolChildWindow()

如有任何帮助或扩展代码示例,我们将不胜感激。

"Directly in XAML" 意思是:把你的 child windows 放在你的根网格里。

<Controls:MetroWindow x:Class="MahApps.Metro.SimpleChildWindow.Demo.MainWindow"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
                      xmlns:simpleChildWindow="clr-namespace:MahApps.Metro.SimpleChildWindow;assembly=MahApps.Metro.SimpleChildWindow"
                      Title="MahApps.Metro Simple ChildWindow Demo"
                      GlowBrush="{DynamicResource AccentColorBrush}"
                      WindowStartupLocation="CenterScreen">

    <Grid x:Name="RootGrid">

        <Grid>
            <!-- main content here -->
        </Grid>

        <simpleChildWindow:ChildWindow x:Name="child01"
                                       CloseByEscape="False"
                                       Closing="Child01_OnClosing"
                                       HorizontalContentAlignment="Stretch"
                                       VerticalContentAlignment="Stretch"
                                       Padding="15"
                                       ChildWindowImage="Error"
                                       Title="TestChild 1">
            <Grid>
                <!-- child content here -->
            </Grid>
        </simpleChildWindow:ChildWindow>

        <simpleChildWindow:ChildWindow x:Name="child02"
                                       ChildWindowWidth="400"
                                       ChildWindowHeight="300"
                                       EnableDropShadow="False"
                                       Title="TestChild 2">
            <Grid>
                <!-- child content here -->
            </Grid>
        </simpleChildWindow:ChildWindow>

    </Grid>

</Controls:MetroWindow>

如果您更喜欢代码隐藏用法,那么您可以像 CustomChildWindow 创建一个自定义的 ChildWindow 并像这样创建和调用它

private async void OpenCustomChildWindow_OnClick(object sender, RoutedEventArgs e)
{
    await this.ShowChildWindowAsync(new CustomChildWindow() { IsModal = false }, RootGrid);
    // or
    //await this.ShowChildWindowAsync(new CustomChildWindow() { IsModal = false }, OverlayFillBehavior.WindowContent);
    // or
    //await this.ShowChildWindowAsync(new CustomChildWindow() { IsModal = true }, OverlayFillBehavior.FullWindow);
}

您也可以在 GitHub 上的主要演示中找到它。

希望对您有所帮助。