[英]How can I make a UIElement show after collapse in upper direction?
On my form, I have a TextBlock
element that initially is collapsed. 在我的表单上,我有一个最初折叠的
TextBlock
元素。 ( TextBlock.Visibility = Visibility.Collapsed
). (
TextBlock.Visibility = Visibility.Collapsed
)。 When some error occurred, it should be shown. 发生某些错误时,应显示出来。 When I use
TextBlock.Visibility = Visibility.Show
, all the controls that are situated under the TextBlock
, are getting down. 当我使用
TextBlock.Visibility = Visibility.Show
,位于TextBlock
下的所有控件均处于关闭状态。
Question: How to dock all the elements that are situated under this TextBlock
in such a way that in case when the TextBlock
is shown, to lift the upper elements? 问题:如何以这种方式停靠位于此
TextBlock
下的所有元素,以防在显示TextBlock
时举起上部元素?
One way to achieve that is through strategic use of the VerticalAlignment
property. 实现此目标的一种方法是通过策略性使用
VerticalAlignment
属性。 Consider the following snippet. 考虑以下代码段。 If this stackpanel is in a container where it has room to grow, it will grow upwards.
如果此堆叠面板放在有增长空间的容器中,它将向上增长。 When you toggle the visibility on the middle textblock, then, it will push the elements above it.
当您在中间文本块上切换可见性时,它将把元素推到其上方。
<StackPanel VerticalAlignment="Bottom">
<TextBlock>I shift upward</TextBlock>
<TextBlock Visibility="Collapsed">Error message here</TextBlock>
<TextBlock>I stay put</TextBlock>
</StackPanel>
我不确定您要问的是什么,但是如果您不希望在TextBlock
可见时其他控件移动,那么它应该以Visibility.Hidden
开头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.