我正在尝试从MahApps包https://github.com/punker76/MahApps.Metro.SimpleChildWindow设置SimpleChildWindow
不幸的是,我不理解样本并且有几个问题:
它说“直接在XAML” - 我应该把它放在哪里?在父窗口中,还是单独的窗口?
await this.ShowChildWindowAsync(new CoolChildWindow(){IsModal = false}); - 我们从哪里获得CoolChildWindow()?
这些问题可能看起来很愚蠢,但我无法在网络上找到任何进一步的信息或样本。
非常感谢任何帮助或扩展代码示例。
答案 0 :(得分:6)
“直接在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>
如果您更喜欢使用代码,那么您可以创建一个自定义的ChildWindow,如CustomChildWindow
并创建并调用它
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的主要演示中找到它。
希望这有帮助。