设置并排 WPF 控件的高度
我有两个 WPF 边框,每个边框都包含一些内容,我希望并排显示这些内容,并且我希望应用以下高度规则:
(1) 左侧边框内的控件的高度将确定两个控件的高度。 (2) 如果左侧边框内的控件的高度小于 200,则两个边框的高度都应为 200(这是最小高度)。 (3) 如果左边框内的控件的高度大于 200,则两个边框都应设置为在右边框不存在时左边框的高度。然后,右侧边框将拉伸或挤压以匹配左侧边框所需的内容。
这在 XAML 中可行吗?还是我必须使用一些代码?如果是这样,什么代码可以工作?
谢谢。
I have two WPF borders, each of which contains some content, which I wish to display side-by-side, and I would like the following height rules to apply:
(1) The height of the control inside the left-hand border will determine the height of both controls.
(2) If the height of the control inside the left-hand border is less than 200, then both borders should have a height of 200 (this is a minimum height).
(3) If the height of the control inside the left-hand border is greater than 200, then both borders should be set to the height the left-hand border would take if the right-hand border did not exist. The right-hand border will then stretch or be squashed to match what the left-hand border desires.
Is this possible in XAML, or do I have to use some code? And if so, what code would work?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该将右侧边框的高度绑定到左侧边框的
ActualHeight
并将两个边框的MinHeight
设置为 200You should bind your right hand border's height to the left one's
ActualHeight
and set both borders to have aMinHeight
of 200为了做这样的事情,你需要一个转换器,这意味着你必须使用一些代码。
将左右边框的高度设置为:
,然后将边框高度的逻辑放入转换器主体中。
for doing something like this you need a converter which means that you have to use some code .
set height of both left and right border to :
and then put your logic for border's heights in the converter body.