wpf - 如何使默认隐藏的控件显示在 Visual Studio 2010 WPF 设计器中?

标签 wpf visual-studio-2010

我有一个具有隐藏可见性的控件,因为它绑定(bind)到 View 模型中的一个属性,其默认值导致它被隐藏。我可以通过 XAML 访问它,但我希望它仍然显示在设计器中。

有没有一种干净的方法可以做到这一点?目前,我正在手动编辑 Visibility 属性以使其显示,但我宁愿不必这样做,以防我忘记将其更改回来。

最佳答案

您可以绑定(bind)到 bool 附加属性 DesignerProperties.IsInDesignMode ,仅当您在设计器内部时才是正确的。这是一个例子:

<Window x:Class="Visitest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:cm="clr-namespace:System.ComponentModel;assembly=PresentationFramework" 
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="conv"/>
    </Window.Resources>
    <Grid>
        <TextBox Margin="8" Background="Green" 
                 Visibility="{Binding (cm:DesignerProperties.IsInDesignMode), RelativeSource={RelativeSource Self}, Converter={StaticResource conv}}"/>           
    </Grid>
</Window>

关于wpf - 如何使默认隐藏的控件显示在 Visual Studio 2010 WPF 设计器中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9877239/

相关文章:

c# - 尝试更新 DispatcherTimer 的间隔,但并不总是有效

c# - mysql odbc 驱动程序在 Visual Studio 2008 上运行良好,但在 Visual Studio 2010 上运行不佳

c++ - OpenCV 未解析的外部符号 - 需要其他库吗?

c++ - 如何强制 MIDL 编译器在 Visual Studio 2010 中使用 "C++ mode"而不是 "C mode"?

c# - 将 ItemsControl 绑定(bind)到 ViewModel 上的 ViewModel 集合

c# - 如何使用子绑定(bind)中的父内容控件?

visual-studio-2010 - 更新到 Windows 10 后 Visual Studio 2010 宏损坏

c - VS2010 中具有无参数原型(prototype)和 64 位架构的前 ANSI C,第二个和第三个参数消失

.net - WPF/银光VS WinRT

c# - Clr 命名空间映射到默认 xaml 命名空间