StackPanel.Visibility 属性未按预期工作?
想象一下,我将以下代码保留在按钮单击中:
if(condition==true)
{
Panel1.Visibility = Visibility.Visible;
Panel.Visibility = Visibility.Collapsed;
}
else
{
Panel.Visibility = Visibility.Visible;
Panel1.Visibility = Visibility.Collapsed;
}
第一次工作,然后其中一个面板折叠,但另一个面板不可见。
有什么想法为什么会发生这种情况吗?
Imagine I keep the below code in button click:
if(condition==true)
{
Panel1.Visibility = Visibility.Visible;
Panel.Visibility = Visibility.Collapsed;
}
else
{
Panel.Visibility = Visibility.Visible;
Panel1.Visibility = Visibility.Collapsed;
}
Works for the first time and then one of the panel collapses but the other panel doesn't become visible.
Any ideas why this is happening ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您修改控件的可见性时,可能是控件 Panel 和 Panel1 的父控件没有调整自身大小。 尝试将 Panel 和 Panel1 放入具有 2 行的网格中,每行的高度设置为“自动”。 我过去在这种层次结构方面取得了成功。 如果这不起作用,您可以发布可以重现的完整且最简单的 Xaml 吗?
Could be that the parent of the controls Panel and Panel1 isn't resizing itself when you modify their Visibility. Try putting Panel and Panel1 in a Grid that has 2 rows, each row having its Height set to Auto. I've had success with that hierarchy in the past. If that doesn't work could you post the complete and simplest Xaml that will repro?
实际上,当我将其移除时,面板的高度已设置为有效......无论如何,感谢回答者
Actually the panels had height set to them when i removed it worked... anyway thanks for answerers