Hi,@Will Pittenger . Welcome to Microsoft Q&A. To position GrayWindow
so that its left side aligns with the left side of the ctrlOpenedBy
image and its bottom edge aligns with the top edge of the ctrlOpenedBy
image, you need to adjust the Left
and Top
properties of GrayWindow
based on the image's position and dimensions. Here is my test sample, you could check it out.
<Window x:Class="WindowInWindow.GrayWindow"
...
WindowStyle="None" Background="Gray" Topmost="False" Title="GrayWindow" Height="100" Width="400">
<StackPanel Orientation="Horizontal">
<Button x:Name="minmize" Width="30" Height="50" Content="-"/>
<Image Source="OIP.jpg" Width="80" Height="50"/>
<Button x:Name="addbutton" Width="30" Height="50" Content="+"/>
</StackPanel>
</Window>
<Window x:Class="WindowInWindow.MainWindow"
...
Loaded="Window_Loaded" Title="MainWindow" Height="450" Width="800">
<Grid Name="grid" Background="Pink">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Bottom">
<Image x:Name="ctrlOpenedBy" Source="th.jpg" Width="40" Height="40" />
<TextBlock Text="search" Width="100" Height="40" FontSize="22" TextAlignment="Center" Background="AliceBlue"/>
</StackPanel>
</Grid>
</Window>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ShowGrayWindow();
}
private void ShowGrayWindow()
{
GrayWindow grayWindow = new GrayWindow();
grayWindow.WindowStartupLocation = WindowStartupLocation.Manual;
grayWindow.Owner = this;
grayWindow.Loaded += (s, e) =>
{
Point imagePosition = ctrlOpenedBy.PointToScreen(new Point(0, 0));
grayWindow.Left = imagePosition.X;
grayWindow.Top = imagePosition.Y - grayWindow.ActualHeight ;
};
grayWindow.Show();
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.