wpf - 禁用 Blend 中绑定(bind)的设计时实例化

标签 wpf visual-studio blend

当我通过 Window.DataContext 绑定(bind)数据集合并且这些集合中有很多项(数千个)时,我的内存就会被消耗到令人沮丧的地步。这些集合在设计时实例化,并在我处理应用程序时显示。我找不到禁用该功能的选项。虽然它在其他项目上很好,但目前对我来说是个障碍。

有人知道如何禁用它吗?

最佳答案

您可以尝试通过d:DesignInstance设置DataContext与IsDesignTimeCreatable=False:

Use d:DesignInstance for create data bindings at design time for a DataContext that is assigned at run time. To create the data binding, you use the data binding builder to create a special design-time data context and set the DesignInstance to a business object type. DesignInstance is a design-time property.

示例:

<Window.DataContext>
    <local:Person />
</Window.DataContext>

<Grid d:DataContext="{d:DesignInstance local:Person, IsDesignTimeCreatable=False}">
    <TextBox Width="100" 
             Height="30" 
             Text="{Binding Path=Name}" />
</Grid>

在这种情况下,DataContext 将不会在设计模式下创建,并且 TextBox 的文本将为空。

关于wpf - 禁用 Blend 中绑定(bind)的设计时实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22956407/

相关文章:

C# 如何跨不同用户保存进程

javascript - 如何在 Visual Studio 中创建一个真正的空白项目 (2017)

visual-studio - 无法在 Visual Studio 自定义中将工具栏项目移动到工具栏菜单中

visual-studio-2012 - 我可以使用 Blend for Visual Studio 2012 制作常规桌面应用程序吗?

c# - 使用 HierarchialdataTemplate 具有多个级别的 WPF TreeView

c# - 如何解决 RibbonApplicationMenu 的绑定(bind)错误

c# - 使用 Telerik 组件正确部署应用程序

c# - SpreadsheetLight 的行数

algorithm - 透明和半透明背景上的混合模式

c# - UWP - 按下指针不起作用