简体   繁体   中英

MahApps - SimpleChildWindow

I'm trying to setup a SimpleChildWindow from the MahApps package

Unfortunately I cound not understand the sample and have a couple of questions:

  1. It says:

Directly in XAML

  • where should I put that?

In the parent's window or is this the separate window?

  1. await this.ShowChildWindowAsync(new CoolChildWindow() { IsModal = false });
    • where do we get that CoolChildWindow() ?

Would be grateful for any help or an extended code sample.

"Directly in XAML" means: put your child windows inside your root grid.

<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>

If you prefer code behind usage, then you can create a custom ChildWindow like CustomChildWindow and create and call it like this

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);
}

You can find this also at the main demo on GitHub.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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