当我通过 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/