WPF ComboBox 弹出位置:底部并与右边缘对齐
我正在尝试创建一个具有非标准下拉对齐的 ComboBox
。基本上,我希望下拉菜单位于 ComboBox 下方,但与 ComboBox 的右边缘而不是左边缘对齐。
使用 PlacementMode="Bottom"
时,正常的 ComboBox
是什么样子:
我想要的:
I尝试使用我的 ComboBox
模板中的 Popup.PlacementMode
属性,但所有可能的值似乎都无法达到我想要的效果。有没有一种简单的方法可以做到这一点,最好是使用纯 XAML?
I'm trying to create a ComboBox
with a non-standard dropdown alignment. Basically, I want the dropdown to be below the ComboBox
, but aligned with the right edge of the ComboBox
instead of the left edge.
What a normal ComboBox
looks like, using PlacementMode="Bottom"
:
What I want:
I tried to play with the Popup.PlacementMode
property in the template of my ComboBox
, but none of the possible values seem to do what I want. Is there a simple way to do it, preferably in pure XAML?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当我打开 Expression Blend 时,我在几秒钟内就想出了解决方案:
有时这个应用程序比手动编写 xaml 更有用,但并不常见。
When I opened Expression Blend, I have come up with the solution within a few seconds:
Sometimes this application is more useful than writing xaml by hands, but not so often.
我将使用 PopUp 的“自定义”放置模式并声明一个回调以将弹出控件放置到正确的位置,如下所示: WPF ComboBox DropDown Placement
看看这里的示例是否适合您:
希望这有帮助,问候
I would use the "Custom" placementmode for the PopUp and declare a callback to place the popup control into the correct position, like it's shown here: WPF ComboBox DropDown Placement
See if an example here would work for you:
hope this helps, regards
有人可以发布完整的xaml代码吗?
我尝试了以下方法:
...经过一些工作和测试后,我找到了一个很好的解决方案...
Can someone post the complete xaml code please?
I've tried the following:
... after some working and testing I've found a good solution...
这有点hacky,但确实有效。您只需要更改组合框样式即可。
弹出窗口 HorizontalOffset 只需获取 PopupContent.ActualWidth-PlacementTarget.ActualWidth 的值。为了获得该值,我使用了 this查尔斯·佩措尔德的把戏。
it's a little hacky, but does work. you just have to change the combobox style.
The popups HorizontalOffset just has to get the value of PopupContent.ActualWidth-PlacementTarget.ActualWidth. To get that value I used this trick from Charles Petzold.