0

I've built a dialog window that i plan to use in my whole application instead of using a message box. Whenever i need to use it, i would call it in the code behind of my Window i'm currently working with this syntax:

public void ShowDialogWindow(object sender, DialogEventArgs e)
{
    DialogWindow dialog = new DialogWindow(e.MessageToShow, DialogType.Error, ButtonsType.OkOnly, this.ActualWidth, this.ActualHeight, this);
    dialog.ShowDialog();
}

this is the constructor of my Dialog Window

public DialogWindow(string messageToDisplay, DialogType dialog, ButtonsType buttons, double width, double height, object Owner)
{
    InitializeComponent();
    this.DataContext = this;
    this.Owner = Owner as Window;
    AWidth = width;
    AHeight = height;
    -----
}

and this is the opening Window tag in the xaml

<Window x:Class="DialogWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        ---
        mc:Ignorable="d" WindowStyle="None" 
        WindowStartupLocation="CenterOwner"
        AllowsTransparency="True" 
        Width="{Binding AWidth}" Height="{Binding AHeight}" 
        MinHeight="720" MinWidth="1080">

Now my problem is. When i call this dialog when the owner is Minimized (having set MinWidth = 1080 and MinHeght = 720) the dialog "kinda" fits (ActualWidth and Actual Height of both Window and DialogWindow are the same, but visually the DialogWindow seems a little bit bigger than the Owner)

Minimized

But when i go full screen it happens this:

Full Screen

Not only the ActualHeight is different to the property AHeight (which is set correctly to the ActualHeight of the Owner), but also is not centered on the Owner window at all, but overflow on my second screen. What cause this, and how can i solve it?

Daniele Sartori
  • 1,674
  • 22
  • 38
  • *"when the owner is Minimized"* - is *minimized* stands for "of minimum size"? There is nothing [minimized](https://stackoverflow.com/q/2841258/1997232) on screenshot. If you want to bind to `ActualHeigt`, then it's [possible](https://stackoverflow.com/q/1083224/1997232), make sure to understand [difference between them](https://stackoverflow.com/q/6403091/1997232). – Sinatr Jan 18 '19 at 15:06
  • @Sinatr in the first screenshot i cutted my desktop. It's minimized in the sense that is not full screen and get the MinHeight and MiniWidth i have set. I'll check those answer to see if i made mistake. – Daniele Sartori Jan 18 '19 at 15:15
  • You don't need binding, since you are passing `owner` parameter (check [guidelines](https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/naming-parameters) for naming btw) you can access its `ActualHeight` and width in constructor. – Sinatr Jan 18 '19 at 15:20

1 Answers1

0

So i'm going to post what it solved my problem, but i have absolutely no idea why that happened, so if anyone has a better answer i will check that as accepted. To solve my problems i removed the binding for width and height and simply added in the constructor of the DialogWindow

this.Width = OwnerActualWidth;
this.Height = OwnerActualHeight;

since i am passing those parameter in input

Daniele Sartori
  • 1,674
  • 22
  • 38