WPF - 使两个控件具有相同的大小
在 WPF 中,有什么方法可以使不同容器中的两个控件具有相同的大小吗?例如,假设您有两个文本框:textbox1 和 textbox2。 Textbox1 位于网格中,当用户调整窗口大小时,其大小可以增大和缩小。 Textbox2 位于窗口的另一部分,我需要它始终具有与 textbox1 相同的大小。有什么办法可以做到这一点吗?
请记住,SharedSizeGroup
将不起作用,因为文本框位于不同的容器中。另外,我尝试将 textbox2 的 height 属性绑定到 textbox1 ,但这似乎也不起作用。最后,我尝试捕获 textbox1 的 SizeChanged
事件,但由于某种原因,其 Height
属性始终为 NaN。
Is there any way to make two controls that are in different containers the same size in WPF? For example, suppose you have two textboxes: textbox1 and textbox2. Textbox1 is in a grid and its size can grow and shrink when the user resizes the window. Textbox2 is in another part of the window and I need it to always have the same size as textbox1. Is there any way to do this?
Keep in mind SharedSizeGroup
will not work because the textboxes are in different containers. Also, I've tried binding textbox2's height property to textbox1 and that doesn't seem to work either. Finally, I tried catching textbox1's SizeChanged
event, but its Height
property is always NaN for some reason.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该绑定到
TextBox
的ActualWidth
和ActualHeight
成员。You should bind to
ActualWidth
andActualHeight
members of theTextBox
.