为 Blend 和 VS 提供设计时 ViewModel 数据 [英] providing designtime ViewModel data for Blend and VS

查看:41
本文介绍了为 Blend 和 VS 提供设计时 ViewModel 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在基于 MVVM 的应用程序中,我必须在设计时提供哪些选项来提供 ViewModel 数据,以便我们的设计人员可以在 Blend3(和 VS 2008)中实际看到一些东西.你是怎么做的?我可以以某种方式使用 mc:ignorable 吗?

In a MVVM based application, what options do I have to provide ViewModel data at design time, so our designers can actually see something in Blend3 (and VS 2008). How are you doing this? Can I utilize mc:ignorable for this somehow?

推荐答案

是的,Expression Blend 可以帮助您解决这个问题.使用数据"选项卡创建与生产数据具有相同形状的示例数据.创建数据源时,请务必取消选中应用程序运行时启用示例数据".

Yes, Expression Blend can help you with this. Use the "Data" tab to create sample data that has the same shape as your production data. When you create the data source, be sure to uncheck "Enable sample data when application is running".

示例数据 http://www.smips.com/brad/stackoverflow/design-model1.jpg

创建示例数据后,将页面的 DataContext 设置为 XAML 中的示例数据.这将使设计人员在 Blend 中打开页面时看到示例数据.

After you've created your sample data, set the DataContext of your page to the sample data in the XAML. This will let the designers see the sample data when they open the page in Blend.

<navigation:Page DataContext={StaticResource MyFakeDesignData}

在 Loaded 处理程序的代码中,编写代码以将 DataContext 设置为真实模型.由于此代码只会在应用运行时运行,并且您已告知示例数据在应用运行时不可用,这意味着正在运行的应用将获得真实数据.

In the code for the Loaded handler, write code to set the DataContext to the real model. Since this code will only run when the app is running, and you've told your sample data to not be available when the app is running, this means the running app will get the real data.

private void Home_Loaded(object sender, RoutedEventArgs e)
{
    DataContext = new MyRealViewModel();
}

这篇关于为 Blend 和 VS 提供设计时 ViewModel 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆