Hi, I want to bring child window such that it's right and bottom overlaps with the parent's right and bottom, but the top is just below the title bar of the parent and the left to the right of the parent's left border as shown in the screenshot.
If I used fixed values for relative dimension as shown in the code, it works on my resolution but not for other users who might have different resolution. How to make this work for all resolutions?
<Window x:Class="WpfAppWindows.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"><Grid><Grid.RowDefinitions><RowDefinition Height="Auto"></RowDefinition></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="Auto"></ColumnDefinition></Grid.ColumnDefinitions><Button Name="btnMain" HorizontalAlignment="Left" Margin="2,2,2,2" Click="btnMain_Click">Main Submit</Button></Grid></Window>
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfAppWindows { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void btnMain_Click(object sender, RoutedEventArgs e) { ChildWindow cw = new ChildWindow(); cw.counter = 1; cw.Owner = Window.GetWindow(this); cw.Top = this.Top + 25; cw.Left = this.Left + 10; cw.Height = this.Height - 25; cw.Width = this.Width - 10; cw.ShowDialog(); } } }
<Window x:Class="WpfAppWindows.ChildWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="ChildWindow" Height="300" Width="300" Loaded="Window_Loaded"><Grid><Grid.RowDefinitions><RowDefinition Height="Auto"></RowDefinition></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="Auto"></ColumnDefinition></Grid.ColumnDefinitions><Button Name="btnChild" HorizontalAlignment="Left" Margin="2,2,2,2" Click="btnChild_Click">Child Submit</Button></Grid></Window>
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace WpfAppWindows { /// <summary> /// Interaction logic for ChildWindow.xaml /// </summary> public partial class ChildWindow : Window { public int counter; public string abc; public ChildWindow() { InitializeComponent(); } private void btnChild_Click(object sender, RoutedEventArgs e) { ChildWindow cw = new ChildWindow(); cw.counter = this.counter + 1; cw.Owner = Window.GetWindow(this); cw.Top = this.Top + 25; cw.Left = this.Left + 10; cw.Height = this.Height - 25; cw.Width = this.Width - 10; cw.ShowDialog(); } private void Window_Loaded(object sender, RoutedEventArgs e) { this.Title = "Child Window - " + counter.ToString(); } } }
Thanks,
-srinivas y.
sri