gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 11:56:56 32 4
gpt4 key购买 nike

我有一个具有隐藏可见性的控件,因为它绑定(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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com