简体   繁体   English

WPF 弹出控件内的控件偏移

[英]Controls inside a WPF Popup Control are offset

First of all, this is my second day designing Forms using WPF.首先,这是我使用 WPF 设计表单的第二天。 At first, I have found that it is easier to manage the controls.起初,我发现管理控件更容易。

I am trying to put some controls inside a WPF Popup and it is behaving differently than I expected.我试图在WPF Popup放置一些控件,但它的行为与我预期的不同。 What seems to be the issue?似乎是什么问题?

<Popup Placement="Center" Height="38" Width="153">
     <StackPanel>
          <TextBlock Background="LightBlue"> This is popup text</TextBlock>
          <Button Content="This is button on a Popup" />
     </StackPanel>
</Popup>

The popup is placed inside a Grid and seems to be centered.弹出窗口放置在 Grid 内并且似乎居中。 But the stackpanel and the controls inside it are placed as in this picture.但是堆栈面板和其中的控件放置在这张图片中。

在此处输入图片说明

I get this behaviour only with the Popup control.我只有使用 Popup 控件才能获得此行为。 What am I missing?我错过了什么?

I would first suggest you to read about what is popup in wpf from here https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/popup-overview#what-is-a-popup .我首先建议您从这里https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/popup-overview#what-is-a-popup阅读 wpf 中的弹出窗口。

The intent of the popup you have writtened here can be to just open a popup when you over your mouse on the grid or when you click mouse on the grid.您在此处编写的弹出窗口的目的可能是在您将鼠标悬停在网格上或在网格上单击鼠标时打开一个弹出窗口。 pop up control can not be showed on your design, insted you can visualize it as how a pop up message box comes on a window.弹出控件无法显示在您的设计中,因此您可以将其可视化为弹出消息框如何出现在窗口中。 The controls you have writtened inside of your popup will be appear when your popup is opened.当您的弹出窗口打开时,您在弹出窗口中编写的控件将出现。

If you want your popup control to aligned properly, first align your it with the grid and then set your stack panel orientation and alignment propery to have a better look.如果您希望弹出控件正确对齐,请首先将其与网格对齐,然后设置堆栈面板方向和对齐属性以获得更好的外观。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM