Reputation: 1549
I'm trying to setup a SimpleChildWindow from the MahApps package
Unfortunately I cound not understand the sample and have a couple of questions:
Directly in XAML
In the parent's window or is this the separate window?
await this.ShowChildWindowAsync(new CoolChildWindow() { IsModal = false });
CoolChildWindow()
? Would be grateful for any help or an extended code sample.
Upvotes: 2
Views: 4791
Reputation: 14611
"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.
Upvotes: 7