WPF 中使用示例数据设计时填充列表框

发布于 2024-09-08 18:39:06 字数 103 浏览 2 评论 0原文

我有一个包含列表框的视图(用户控件)。 在运行时,列表框将填充另一个视图(也是用户控件)的实例。 如何在设计时(在 Blend 和 Cider 中)使用本身填充有示例数据的示例视图填充列表框?

I have a view (usercontrol) that contains a listbox.
At runtime the listbox will be populated with instances of another view (also a usercontrol).
How can I populate the listbox in design-time (in Blend and Cider) with sample views that are themselves populated with sample data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁的新欢旧爱 2024-09-15 18:39:06

使用 VS2010,您可以使用设计时属性(适用于 SL 和 WPF)。无论如何,我通常有一个模拟数据源,所以这只是一个问题:

  • 添加名称空间声明

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

  • 将模拟数据上下文添加到窗口/控件资源

    ;
        
    
    
  • 设置设计时数据上下文

     ...
    

效果很好。

Using VS2010 you can use Design-Time attributes (works for both SL and WPF). I usually have a mock data-source anyway so it's just a matter of:

  • Adding the namespace declaration

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

  • Adding the mock data context to window/control resources

    <UserControl.Resources>
        <ViewModels:MockXViewModel x:Key="DesignViewModel"/>
    </UserControl.Resources>
    
  • Setting design-time data context

    <Grid d:DataContext="{Binding Source={StaticResource DesignViewModel}}"> ...
    

Works well enough.

春风十里 2024-09-15 18:39:06

您可能会找到 BookLibrary 示例应用程序>WPF 应用程序框架 (WAF) 很有趣。它使用 Visual Studio 2010 和 Expression Blend 4 的新设计时支持。请下载 .Net4 版本的 WAF。

You might find the BookLibrary sample application of the WPF Application Framework (WAF) interesting. It uses the new design-time support of Visual Studio 2010 and Expression Blend 4. Please download the .Net4 version of WAF.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文