【发布时间】:2019-06-12 20:35:52
【问题描述】:
我已经构建了一个对话框窗口,我计划在整个应用程序中使用它而不是使用消息框。每当我需要使用它时,我都会在我正在使用此语法的 Window 后面的代码中调用它:
public void ShowDialogWindow(object sender, DialogEventArgs e)
{
DialogWindow dialog = new DialogWindow(e.MessageToShow, DialogType.Error, ButtonsType.OkOnly, this.ActualWidth, this.ActualHeight, this);
dialog.ShowDialog();
}
这是我的对话框窗口的构造函数
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;
-----
}
这是 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">
现在我的问题是。当我在所有者最小化(设置 MinWidth = 1080 和 MinHeght = 720)时调用此对话框时,对话框“有点”适合(Window 和 DialogWindow 的 ActualWidth 和 Actual Height 相同,但在视觉上 DialogWindow 似乎有点大比所有者)
但是当我全屏时,它会发生这种情况:
ActualHeight 不仅与属性 AHeight 不同(正确设置为 Owner 的 ActualHeight),而且根本不在 Owner 窗口的中心,而是在我的第二个屏幕上溢出。这是什么原因造成的,我该如何解决?
【问题讨论】:
-
“当所有者最小化时” - 最小化 代表“最小尺寸”吗?截图上没有minimized。如果要绑定
ActualHeigt,那就是possible,一定要了解difference between them。 -
@Sinatr 在第一个屏幕截图中我剪切了我的桌面。它在不是全屏的意义上被最小化并获得我设置的 MinHeight 和 MiniWidth。我会检查那些答案,看看我是否弄错了。
-
你不需要绑定,因为你传递了
owner参数(检查guidelines命名顺便说一句)你可以在构造函数中访问它的ActualHeight和宽度。