我只是在玩 MVVM Light,我想我已经明白了,但我有一个问题。
我正在使用为我的数据库 (SQLCE) 生成类、映射等的 SQL Server CE 工具箱。其中一个表称为 Profile,我想将其用作我也可以绑定的属性。这是我的 ViewModel 代码
public class ProfileViewModel : ViewModelBase
{
private Profile profile; // Profile is the class created by SQLCE Toolbox for table mapping
public Profile UserProfile
{
get { return profile; }
set
{
profile = value;
RaisePropertyChanged("UserProfile");
}
}
public ProfileViewModel()
{
if (IsInDesignMode)
{
// Code runs in Blend --> create design time data.
UserProfile = new Profile()
{
Name = "NA",
Age = 22
}
}
else
{
// Code runs "for real"
UserProfile = GetProfile();
}
}
}
在 Expression blend 中,我可以看到 ViewModel 但看不到 Profile 属性,所以我猜测某处正在生成异常。
我确实尝试将混合作为一个过程附加,但没有出现错误。经过一点阅读,我发现混合无法连接到数据库,因此您必须在设计模式下弥补一些数据。我只是尝试做UserProfile = new Profile()
,但我猜它仍在尝试使用数据库来创建它?
编辑:好的,我认为我遇到的问题与使用 SQLCE 有关。如果我尝试使用 WPF 和 MS SQL 进行类似的操作,那么一切正常。
编辑 2:这与数据库明确相关。如果我从上面的代码中删除公共属性 UserProfile,则可以从 Blend 中看到所有其他属性(我的代码中未显示)。如果我把它加回去,那么没有一个是可见的。那么我怎样才能使它可混合呢?