View 中DataContext的设置问题

原文地址http://devlicio.us/blogs/christopher_bennage/archive/2010/03/29/d-designinstance-in-blend-4.aspx

在blend 中设计View的时候View的DataContext 常常从父级继承。这是在Dinding的时候出现不方便。

selecting the data binding editor for the ItemsSourceThe depressingly empty Data Context tab.

可以在xaml 中添加如下代码

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

d:DataContext="{d:DesignInstance {x:Type vm:MainWindowViewModel}}

这句话不会实例化一个MainWindowViewModel类,而是通知设计器 该View 的ViewModel类型。以便在属性窗口中进行binding的设置。从而简化编程过程。

例子:

<Grid d:DataContext="{d:DesignInstance {x:Type vm:MainWindowViewModel}}">

</Grid>

设置之后,效果如下

a really useful data binding engine

posted @ 2011-03-31 15:42  孤狼晖  阅读(685)  评论(0编辑  收藏  举报