积极答复者
WPF xaml中声明类对象作为Window的DataContext时,提示‘无法创建 xxx 的实例’!!!

问题
-
大家好:
我最近开始学习WPF技术。
现在遇到一个问题:
在我的Window的xaml中我要声明一个类来作为该Window的数据上下文(DataContext),我写在xaml中的目的是为了
更好的将View和Model分离。(我在项目里使用了 Prism框架来做MVVM模式)
代码如下:
<Window x:Class="LoginView.SystemWindow.LoginShell" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:VM="clr-namespace:ViewModel.LoginViewModel;assembly=ViewModel" Title="登录My WP" Height="300" Width="370" WindowStyle="None" AllowsTransparency="True" ResizeMode="NoResize" MouseLeftButtonDown="Window_MouseDown" Background="Transparent" WindowStartupLocation="CenterScreen" > <Window.DataContext> <VM:LoginVM/> --->就是这一样提示:无法创建LoginVM的实例. </Window.DataContext> </Window>
上面的xaml代码里 在声明Window.DataContext的时候,提示“无法创建LoginVM的实例.”, 导致设计器不可编辑。
但是我的程序都能编译通过并且正常运行。
请问各位这是什么原因造成的?是不是xaml中的写法有问题???
注意:我的 LoginVM类是放在另一个项目ViewModel里的(名称空间:ViewModel.LoginViewModel.LoginVM)!!!!
!!
欢迎交流指教 MSN:mangonic@hotmail.com
答案
-
LoginVM的构造函数有没有无参的,如果没有 加一个
Sheldon _Xiao
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
全部回复
-
LoginVM的构造函数有没有无参的,如果没有 加一个
Sheldon _Xiao
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
关于你的新问题 你可以开个新的帖子, 我会在那里给你回答,我们建议一个帖子一个问题。
Sheldon _Xiao
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.