Are Expression Blend design-time specific visuals possible?

陌路散爱 提交于 2019-12-13 14:54:35

问题


I'm trying to design some UserControl classes in Blend 3. I want parts of them to be "collapsed" when created at runtime, but I want to be able to edit their component parts without fiddling with code every time I want to build.

It works with sample datasources, as the following example illustrates. But it doesn't appear to work with other properties... or am I doing something wrong?

With a sample data source SDS_AIVertexAction We can do this in Expression Blend:

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
...>


<Grid x:Name="LayoutRoot" 
    d:DataContext="{Binding Source={StaticResource SDS_AIVertexAction}}" >
    ...
</Grid>

But it does not seem to be possible to do this:

 <Label Content="{Binding Name}" Visibility="Collapsed" d:Visibility="Visible" />

I realise I could change visibility "on loaded" but I'd really rather not type all that guff every time I make a control like this. Does someone know a secret that lets us do this?


回答1:


Well, here's a guess.

The d: namespace is for stuff that is respected at design time but ignored at runtime. So we want to set the visibility somehow within the d: namespace where it overrides visibility set for runtime.

Inline styles override styles set globally or via StaticResource, so I'd suggest doing this (from memory--don't just copy and paste it, understand the concept):

<UserControl.Resources>
  <Style x:Key="invisible" TargetType="Label">
    <Setter Property="Visibility" Value="Collapsed"/>
  </Style>
</UserControl.Resources>
<!-- ... -->
<Label Style="{StaticResource invisible}" d:Visibility="Visible" />


来源:https://stackoverflow.com/questions/1367684/are-expression-blend-design-time-specific-visuals-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!