我正在使用 MVVM Light、Sql Server Compact Toolkit 和 windows phone 7。
我创建了一个 sql server compact 3.5 数据库,然后使用该工具包为每个表生成数据上下文和域类。
看起来像这样
[global::System.Data.Linq.Mapping.TableAttribute(Name = "ContactGroups")]
public partial class ContactGroup : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private int _Id;
private string _Title;
private System.DateTime _LastUpdated;
private EntitySet<GContact> _GContacts;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnIdChanging(int value);
partial void OnIdChanged();
partial void OnTitleChanging(string value);
partial void OnTitleChanged();
partial void OnLastUpdatedChanging(System.DateTime value);
partial void OnLastUpdatedChanged();
#endregion
public ContactGroup()
{
this._GContacts = new EntitySet<GContact>(new Action<GContact>(this.attach_GContacts), new Action<GContact>(this.detach_GContacts));
OnCreated();
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Id", DbType = "Int NOT NULL", IsPrimaryKey = true)]
public int Id
{
get
{
return this._Id;
}
set
{
if ((this._Id != value))
{
this.OnIdChanging(value);
this.SendPropertyChanging();
this._Id = value;
this.SendPropertyChanged("Id");
this.OnIdChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Title", DbType = "NVarChar(100) NOT NULL", CanBeNull = false)]
public string Title
{
get
{
return this._Title;
}
set
{
if ((this._Title != value))
{
this.OnTitleChanging(value);
this.SendPropertyChanging();
this._Title = value;
this.SendPropertyChanged("Title");
this.OnTitleChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_LastUpdated", DbType = "DateTime NOT NULL")]
public System.DateTime LastUpdated
{
get
{
return this._LastUpdated;
}
set
{
if ((this._LastUpdated != value))
{
this.OnLastUpdatedChanging(value);
this.SendPropertyChanging();
this._LastUpdated = value;
this.SendPropertyChanged("LastUpdated");
this.OnLastUpdatedChanged();
}
}
}
[global::System.Data.Linq.Mapping.AssociationAttribute(Name = "FK_GContacts_ContactGroups", Storage = "_GContacts", ThisKey = "Id", OtherKey = "ContactGroups_Id", DeleteRule = "NO ACTION")]
public EntitySet<GContact> GContacts
{
get
{
return this._GContacts;
}
set
{
this._GContacts.Assign(value);
}
}
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanging()
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}
protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private void attach_GContacts(GContact entity)
{
this.SendPropertyChanging();
entity.ContactGroup = this;
}
private void detach_GContacts(GContact entity)
{
this.SendPropertyChanging();
entity.ContactGroup = null;
}
}
然而,当我尝试使其可混合时(即制作假数据,因此当我进入混合时,我可以更好地使用它而不是查看空框)混合中没有任何显示
当我有一个没有它的简单域时
public class ContactGroup
{
public int Id { get; set; }
public string Title { get; set; }
public DateTime LastUpdated { get; set; }
public List<GContacts> Contacts { get; set; }
public ContactGroup()
{
Contacts = new List<GContacts>();
}
}
然后在我的视图模型定位器中
if (ViewModelBase.IsInDesignModeStatic)
{
SimpleIoc.Default.Register<IContactService, DesignContactService>();
}
else
{
SimpleIoc.Default.Register<IContactService, DesignContactService>();
}
编辑 问题线看起来是这样
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
当我删除它时,混合再次显示数据。