我如何将弹出窗口大小设置为它的内容?

Ehs*_*adi 3 c# wpf xaml

我在WPF中有一个Popup控件,它动态地包含它的内容,每次我需要设置它的大小,这怎么可以自动完成,所以它总是保持它的大小与它的内容大小.

<Popup 
      Name="popup1" 
      StaysOpen="False" 
      PlacementTarget="{Binding ElementName=myButton}" 
      Placement="Custom" 
      PopupAnimation="Fade" 
      AllowsTransparency="True">
Run Code Online (Sandbox Code Playgroud)

Aar*_*ver 6

A Popup already sizes according to content.

By default, a Popup is automatically sized to its content. When auto-sizing occurs, some bitmap effects may be hidden because the default size of the screen area that is defined for the Popup content does not provide enough space for the bitmap effects to display.

Popup content can also be obscured when you set a RenderTransform on the content. In this scenario, some content might be hidden if the content of the transformed Popup extends beyond the area of the original Popup. If a bitmap effect or transform requires more space, you can define a margin around the Popup content in order to provide more area for the control.

Perhaps your Popup content is having sizing issues due to you restricting growth within your layout container? Your Popup is thus sized accordingly but your Grid for example may have a fixed width.