在 Visual Studio 设计器中隐藏 WPF 元素 [英] Hide WPF elements in Visual Studio designer

查看:29
本文介绍了在 Visual Studio 设计器中隐藏 WPF 元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WPF 表单,基本上如下所示:

I have a WPF form which basically looks like this:

<Window ...>
  <Grid>
    <DockPanel>
      [content shown during normal operation]
    </DockPanel>

    <Grid Background="#CCCC" Visibility="Hidden">
      [overlay grid which is only shown during special circumstances]
    </Grid>
  </Grid>
</Window>

覆盖网格会隐藏其他所有内容(即正常内容"),并且仅在特殊情况下(即网络连接中断时)才会显示.这在运行程序时非常有效.

The overlay grid hides everything else (i.e. the "normal content") and is only shown under special circumstances (i.e. if the network connection goes down). This works perfectly fine when running the program.

现在,在设计模式中,问题在于 Visual Studio 忽略了 Visibility="Hidden".通常,这是完全合理的(毕竟,我希望能够编辑隐藏的 UI 元素),但就我而言,这很烦人,因为它阻止我在设计器中编辑 DockPanel 中的内容.

Now, in design mode, the problem is that Visual Studio ignores the Visibility="Hidden". Usually, this makes perfect sense (after all, I want to be able to edit the hidden UI elements), but in my case it's annoying, because it prevents me from editing the stuff in the DockPanel in the designer.

所以,我想做的是这样的:

So, what I'd like to do is something like that:

<Grid Background="#CCCC" Visibility="Hidden" VS.ShowInDesigner="False">
  [overlay grid which is only shown during special circumstances]
</Grid>

但是,唉,没有这样的财产,或者至少我不知道.有什么想法吗?

But, alas, there is no such property, or at least none that I know of. Any ideas?

推荐答案

从 VS2012 开始,您可以只使用 Blend 命名空间 IsHidden 属性:

Starting from VS2012 you can just use the Blend namespace IsHidden attribute:

  • 如果还没有,请添加 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  • 仅在设计时将 d:IsHidden="true" 放在要隐藏的元素上

这篇关于在 Visual Studio 设计器中隐藏 WPF 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆