我正在尝试从MahApps软件包中设置SimpleChildWindow

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

  • 它说:


  • 我应该放在哪里?

  • 在 parent 的窗口中还是这是单独的窗口?
  • await this.ShowChildWindowAsync(new CoolChildWindow() { IsModal = false });
  • 我们从哪里获得CoolChildWindow()

  • 感谢您的帮助或扩展的代码示例。

    最佳答案

    “直接在XAML中”是指:将子窗口放在根网格中。

    <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上的主要演示中找到它。

    希望这可以帮助。

    关于c# - MahApps-SimpleChildWindow,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37799799/

    10-11 23:58