gpt4 book ai didi

c# - MahApps - SimpleChildWindow

转载 作者:行者123 更新时间:2023-11-30 20:19:54 25 4
gpt4 key购买 nike

我正在尝试设置 SimpleChildWindow来自 MahApps 包

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

  1. 它说:

Directly in XAML

  • 我应该把它放在哪里?

在父窗口中还是在单独的窗口中?

  1. 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com