WPF 文本框高度等于父高度减去 50 像素?
我成功地让文本框根据父边框高度调整大小,但我需要文本框的高度实际上比父边框小 50 像素。
有什么想法如何实现这一目标?
我正在使用的代码是
<Border VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
<TextBox x:Name="txtActivityNotes" HorizontalAlignment="Stretch" Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border}}, Path=ActualHeight}" AcceptsReturn="True" VerticalContentAlignment="Top" TextWrapping="WrapWithOverflow" VerticalScrollBarVisibility="Auto" />
</Border>
I'm successfully getting a TextBox to resize with a parent Border height but I need the TextBox to actually be 50 pixels smaller in height than the parent Border.
Any ideas how to achieve this?
The code I'm using is
<Border VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
<TextBox x:Name="txtActivityNotes" HorizontalAlignment="Stretch" Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border}}, Path=ActualHeight}" AcceptsReturn="True" VerticalContentAlignment="Top" TextWrapping="WrapWithOverflow" VerticalScrollBarVisibility="Auto" />
</Border>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下边距不能设置为50吗?
Can't you just set a bottom margin of 50?
我尝试过遵循并且有效。
将以下内容添加到 xaml 中的文本框:
这里,AncestorType 是包含文本框的容器的类型。就我而言,它是“网格”。
并且还添加边距,
以与下面的边框保持距离。
============
哎呀抱歉我在同一页面上发布了。!
I've tried following and it works.
add following to text box in xaml:
Here, AncestorType is type of container containing the textBox. In my case it was 'Grid'.
And also add margin like,
to keep distance from border below.
============
oops sorry i posted on the same page.!
如何在绑定上使用转换器将高度减去负 50
这是使用转换器的示例
how about using a converter on the binding to minus 50 off the height
heres an example of using a converter