WPF 中的 XAML 弹出窗口溢出 [英] XAML popup overflow in WPF

查看:38
本文介绍了WPF 中的 XAML 弹出窗口溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的弹出窗口:

I have a Popup that looks like this:

<local:toolbox_popup x:Name="PopupBaseMapLayers" Grid.Row="1" StaysOpen="False"PopupAnimation="Fade" VerticalAlignment="Stretch" AllowsTransparency="True"PlacementTarget="{Binding ElementName=tooldropdown}" PlacementRectangle="-280,0,0,0" ><堆栈面板><ScrollViewer VerticalScrollBarVisibility="Auto" VerticalAlignment="Stretch" ></SrollViewer></StackPanel></local:toolbox_popup>

所以当用户点击一个按钮时会出现Popup,但是由于时间长,popup会溢出到窗口外.有没有办法将溢出隐藏在窗口中,或者将弹出窗口的高度设置为动态,无论窗口大小如何?

So the Popup appears when the user clicks a button, but the popup overflows outside the window because of how long it is. Is there a way to either have the overflow hidden within the window or set the height of the popup to be dynamic with whatever the size of the window is?

推荐答案

在您的问题中需要考虑很多事情.可行的最小宽度应该是多少,用于显示此Popup 的按钮究竟在哪里.这些 Buttons 是否位于窗口的右下角?

A lot many things needs to be considered in your question. What should be the minimum width which would be feasible, where exactly are the buttons which are used to show this Popup. Are these Buttons are at right bottom of the Window ?

综合考虑,我建议以下设置可以解决您的问题.

Consider everything, I suggest following settings which will solve your problem.

<Popup x:Name="Popup1" Placement="Relative" PlacementTarget="{Binding ElementName=Grd}" StaysOpen="False"  Width="{Binding PlacementTarget.ActualWidth, RelativeSource={RelativeSource Self}}">
...
</Popup>

这里我将PlacementTarget 设置为最顶层的容器Grid.如果我们点击外面的任何地方,StatysOpen = False 会导致 Popup 消失.您甚至可以选择 Window 作为您的 PlacementTarget.

Here I have set PlacementTarget to be the top most container Grid. StatysOpen = False causes Popup to disappear if we click anywhere outside. You can even choose Window as your PlacementTarget.

然后还有一个叫做PlacementRectangle的属性来放置它,你可以应用Binding和一个Converter来返回Rectangle.

Then there is another property called PlacementRectangle to place it, you can apply Binding with a Converter to return Rectangle.

告诉我这是否能解决您的问题.

Let me know if this solves your problem.

这篇关于WPF 中的 XAML 弹出窗口溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆