我尝试在使用WCF获取数据的客户端中应用MVVM。 首先,它适用于MVVM绑定。但我一直陷入困境。 在我的程序中,有一个从窗口继承的“MainWindows”作为基本UI,并包含一个名为“HomeControl”的用户控件。当我添加线 “this.DataContext = new HomeViewModel();”在HomeContorl.xaml.cs中。 HomeControl没有在主窗口显示并告诉我
"
In the ServiceModel client configuration section, can not find a reference to the Agreement "ITestWcf" default endpoint element. This may be because the application configuration file is not found , or because the client can not find endpoint element with this agreement matched elements .
In System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors (ServiceEndpoint serviceEndpoint, String configurationName)
In System.ServiceModel.ChannelFactory.ApplyConfiguration (String configurationName, Configuration configuration)
In System.ServiceModel.ChannelFactory.ApplyConfiguration (String configurationName)
In System.ServiceModel.ChannelFactory.InitializeEndpoint (String configurationName, EndpointAddress address)
In System.ServiceModel.ChannelFactory `1 .. ctor (String endpointConfigurationName, EndpointAddress remoteAddress)
In System.ServiceModel.ConfigurationEndpointTrait `1.CreateSimplexFactory ()
In System.ServiceModel.ConfigurationEndpointTrait `1.CreateChannelFactory ()
In System.ServiceModel.ClientBase `1.CreateChannelFactoryRef (EndpointTrait` 1 endpointTrait)
In System.ServiceModel.ClientBase `1.InitializeChannelFactoryRef ()
In System.ServiceModel.ClientBase `1 .. ctor ()
In TestWcfClient .. ctor () Location D: \ Cswork \ Visual Studio 2010 \ Projects \ InterfaceCom - bk20131113 - copy \ Client0.1 \ Client0.1 \ testproxy.cs: line number 995
In TestViewModel.BaseViewModel .. ctor () Location D: \ Cswork \ Visual Studio 2010 \ Projects \ InterfaceCom - bk20131113 - copy \ Client0.1 \ Client0.1 \ BaseViewModel.cs: line 18
In TestViewModel.LoginViewModel .. ctor () Location D: \ Cswork \ Visual Studio 2010 \ Projects \ InterfaceCom - bk20131113 - copy \ Client0.1 \ Client0.1 \ LoginViewModel.cs: line 38
In Client0_1.HomeControl .. ctor () Location D: \ Cswork \ Visual Studio 2010 \ Projects \ InterfaceCom - bk20131113 - copy \ Client0.1 \ Client0.1 \ HomeControl.xaml.cs: line 28
"
我更改了app.config中的相关内容,但问题仍然存在。只有我删除了之前提到的“this.DataContext = new HomeViewModel()”这一行,问题就消失了。是什么原因以及如何使其有效?非常感谢。