代码改变世界

设计时属性 – Design Runtime

2013-02-22 22:53  deeloo  阅读(515)  评论(0)    收藏  举报

为了改善设计时开发体验,因此提供了一种特殊的设计时属性。它可以添加到任何的WPF element,这些属性定义在一个特殊的命名空间。另外还有一个命名空间来告诉XAML 转换器设计时属性是可被忽略的。

<Window 
   xmlns:d ="http://schemas.microsoft.com/expression/blend/2008"
   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
   mc:Ignorable="d" />

前缀 d: 为设计时属性,前缀mc:Ignorable=”d” 表明d下面的属性可以在运行时忽略。 下表是MSDN定义的设计时属性:

 

设计时属性 描述
d:DesignHeight
d:DesignWidth
Specifies the height and width of the root element at design time, independently of the height at run time
d:DataContext Specifies a design-time data context for a control and its children. A common pattern is to declare control bindings in XAML view, and to set the DataContext that is used to populate the bindings at run time. If you are using this pattern, you can set d:DataContext so that the designer is aware of the shape of your types. This enables you to use the data binding builder to create bindings in Design view.
d:DesignInstance Used as part of a d:DataContext or d:DesignSource declaration. Specifies the type that you can use as a data source for binding to controls in the designer. The type does not need to be creatable in XAML.
d:DesignData Used as part of a d:DataContext or d:DesignSource declaration. Specifies a XAML file that contains sample data for use at design time. Use the DesignData or DesignDataWithDesignTimeCreatableTypes build actions to integrate your sample data with your project. Read-only properties can be assigned values.
d:DesignSource Specifies a design-time data source for a CollectionViewSource. This makes the designer aware of the shape of your types. This enables you to use the data binding builder to create bindings.
d:IsDesignTimeCreatable In the d:DesignInstance markup extension, specifies that the design instance is created from your type, instead of a designer-generated substitute type.
d:CreateList In the d:DesignInstance markup extension, specifies that the design instance is a list of the specified type.
d:Type In the d:DesignInstance markup extension, specifies the type to create. Use d:IsDesignTimeCreatable to specify whether an instance or your type or a designer-generated substitute type is created.