先生们。我在 Silverlight 项目 MainPage.xaml 中有以下定义:
<UserControl
xmlns:model="clr-namespace:Engine.Silverlight.Web.Views;assembly=Engine.Login.Model"
d:DataContext="{d:DesignInstance Type=model:DesignTimeModel, IsDesignTimeCreatable=True}">...
和 Engine.Login.Model 项目中的类,用于设计时数据绑定(对于预初始化的属性,一切正常,但是):
public class DesignTimeModel : INotifyPropertyChanged
{
public DesignTimeModel()
{
var d = Deployment.Current.Dispatcher;
d.BeginInvoke(
() =>
{
CacheClient c = new CacheClient();
c.GetResourcesCompleted +=(s,e)=>
{
d.BeginInvoke(
() => this.Resources = e.Result);
};
c.GetResourcesAsync();
}
);
不幸的是,在 WCF 请求完成后,我得到了一个 System.ObjectDisposedException (我尝试通过附加到第一个 VS 实例进程来使用不同的 VS 实例进行调试,但它没有帮助 - 同样的错误,没有其他信息):
System.ObjectDisposedException
Cannot access a disposed object.
Object name: 'Dispatcher'.
at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
我假设 Dispatcher 行为在设计模式中有所不同。您能帮我解决在 VS2010 XAML 设计器中使用 WCF 获取设计时数据的问题吗?