jgl*_*uie 7 wpf visual-studio-2010
我有一个具有隐藏可见性的控件,因为它绑定到视图模型中的属性,其默认值使其隐藏.我可以通过XAML访问它,但我仍然希望它仍然显示在设计器中.
这样做有干净的方法吗?现在,我手动编辑Visibility属性以使其显示,但我宁愿不必这样做,以防我忘记更改它.
小智 5
您可以绑定到布尔附加属性DesignerProperties.IsInDesignMode
,仅当您在设计器中时才为 true。下面是一个例子:
<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>
Run Code Online (Sandbox Code Playgroud)