Wpf 由d:DesignInstance创建的对象的Dispose

Wpf 由d:DesignInstance创建的对象的Dispose,wpf,dispose,design-time-data,Wpf,Dispose,Design Time Data,有没有办法处置由以下标记创建的对象 <UserControl x:Class="NodeBrowser" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/ma

有没有办法处置由以下标记创建的对象

<UserControl x:Class="NodeBrowser"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="344" d:DesignWidth="589"
         d:DataContext="{d:DesignInstance Type=local:NodeBrowserViewModel, IsDesignTimeCreatable=True}"
         >
    <Whatever...>
</UserControl>
我的设计实例创建了一个到数据库的连接,所以第一次设计时测试此控件时一切正常,但第二次它抛出异常,因为第一次设计时数据仍然有一个打开的连接

现在我知道这没有什么意义,但它仍然带来了一个问题,即通过d:DesignInstance创建的对象似乎永远不会被处理,即使它们实现了IDisposable


是否有任何解决方案,或者我们基本上被迫提供不需要IDisposable用于设计数据的轻量级对象?

您可以使用Microsoft Expression Blend在设计模式下模拟数据,而不是在设计时访问实际数据库,请查看此项。

,您可以使用Microsoft Expression Blend在设计模式下模拟数据,请查看此项