【发布时间】:2014-11-10 09:12:03
【问题描述】:
父集合绑定到具有分层gridview结构的radGridView。
有没有办法在内部集合发生变化时触发父属性
父对象:
public class CoverHierarchical : EditableModelBase<CoverHierarchical>
{
#region Attribute Declarations
private Int32 m_iId;
private string m_sName = "";
private bool m_bIsChanged;
private ObservableCollection<CoverContentBO> m_oCoverContent;
#endregion
/// <summary>
/// Get or set the id.
/// </summary>
public Int32 Id
{
get { return this.m_iId; }
set
{
if (this.m_iId != value)
{
this.IsChanged = true;
this.m_iId = value;
RaisePropertyChanged("Id");
}
}
}
/// <summary>
/// Get or set the name.
/// </summary>
public string Name
{
get { return this.m_sName; }
set
{
if (this.m_sName != value)
{
this.IsChanged = true;
this.m_sName = value;
RaisePropertyChanged("Name");
}
}
}
/// <summary>
/// Get or set the CoverContent Collection.
/// </summary>
public ObservableCollection<CoverContentBO> CoverContentCollection
{
get { return this.m_oCoverContent; }
set
{
if (this.m_oCoverContent != value)
{
this.IsChanged = true;
this.m_oCoverContent = value;
RaisePropertyChanged("CoverContentCollection");
}
}
}
/// <summary>
/// Get or set the changed flag.
/// </summary>
public bool IsChanged
{
get { return this.m_bIsChanged || this.CoverContentCollection.Any(i=>i.IsChanged); }
set
{
if (this.m_bIsChanged != value)
{
this.m_bIsChanged = value;
RaisePropertyChanged("IsChanged");
}
}
}
#endregion
}
和子对象
[Serializable]
public class CoverContentBO : EditableModelBase<CoverContentBO>
{
#region Attribute Declarations
private Int32 m_iCoverId;
private Int32 m_iId;
private bool m_bIsChanged;
#endregion
#region Public Properties
/// <summary>
/// Get or set the cover id.
/// </summary>
public Int32 CoverId
{
get { return this.m_iCoverId; }
set
{
if (this.m_iCoverId != value)
{
this.IsChanged = true;
this.m_iCoverId = value;
RaisePropertyChanged("CoverId");
}
}
}
/// <summary>
/// Get or set the id.
/// </summary>
public Int32 Id
{
get { return this.m_iId; }
set
{
if (this.m_iId != value)
{
this.IsChanged = true;
this.m_iId = value;
RaisePropertyChanged("Id");
}
}
}
/// <summary>
/// Get or set the changed flag.
/// </summary>
public bool IsChanged
{
get { return this.m_bIsChanged; }
set
{
if (this.m_bIsChanged != value)
{
this.m_bIsChanged = value;
RaisePropertyChanged("IsChanged");
}
}
}
#endregion
}
在 ViewModel 中
public ObservableCollection<CoverHierarchical> CoverHierarchicalCollection
{
get { return m_CoverHierarchicalCollection; }
set
{
if (m_CoverHierarchicalCollection != value)
{
m_CoverHierarchicalCollection = value;
OnPropertyChanged();
}
}
}
CoverHierarchicalCollection 绑定到视图。如果用户编辑子网格,则更改发生在子网格中。在更改子内部集合(CoverContentCollection)字段时,有什么方法可以触发父级的IsChanged 属性。
【问题讨论】:
-
我已将您的问题标记为重复的问题比您的问题更笼统。但是,当您的子视图模型发生变化时,您仍然可以使用它的解决方案来通知您的父视图模型。