Question

When I bind data collections through the Window.DataContext and I have a lot of items in those collections (thousands), my memory simply gets eaten up to the point where it's frustrating. Those collections are instantiated during design time and get displayed while I'm working on the application. I couldn't find an option to disable that feature. While it's nice on other projects, it's handicapping me at the moment.

Does anyone know how to disable it?

Was it helpful?

Solution

You can try set the DataContext via d:DesignInstance with 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.

Example:

<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>

In this case, DataContext will not be created in design mode and Text of TextBox will be empty.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top