using System.Collections.ObjectModel;
using Catel.Data;
#if !SILVERLIGHT
using System;
using System.Runtime.Serialization;
#endif
namespace Catel.Examples.Models
{
/// <summary>
/// Family Data object class which fully supports serialization, property changed notifications,
/// backwards compatibility and error checking.
/// </summary>
#if !SILVERLIGHT
[Serializable]
#endif
public class Family : SavableDataObjectBase<Family>
{
#region Variables
#endregion
#region Constructor & destructor
/// <summary>
/// Initializes a new object from scratch.
/// </summary>
public Family()
{ }
#if !SILVERLIGHT
/// <summary>
/// Initializes a new object based on <see cref="SerializationInfo"/>.
/// </summary>
/// <param name="info"><see cref="SerializationInfo"/> that contains the information.</param>
/// <param name="context"><see cref="StreamingContext"/>.</param>
protected Family(SerializationInfo info, StreamingContext context)
: base(info, context) { }
#endif
#endregion
#region Properties
/// <summary>
/// Gets or sets the father.
/// </summary>
public Person Father
{
get { return GetValue<Person>(FatherProperty); }
set { SetValue(FatherProperty, value); }
}
/// <summary>
/// Register the property so it is known in the class.
/// </summary>
public readonly PropertyData FatherProperty = RegisterProperty("Father", typeof(Person), null);
/// <summary>
/// Gets or sets the mother.
/// </summary>
public Person Mother
{
get { return GetValue<Person>(MotherProperty); }
set { SetValue(MotherProperty, value); }
}
/// <summary>
/// Register the property so it is known in the class.
/// </summary>
public readonly PropertyData MotherProperty = RegisterProperty("Mother", typeof(Person), null);
/// <summary>
/// Gets or sets the children.
/// </summary>
public ObservableCollection<Person> Children
{
get { return GetValue<ObservableCollection<Person>>(ChildrenProperty); }
set { SetValue(ChildrenProperty, value); }
}
/// <summary>
/// Register the property so it is known in the class.
/// </summary>
public readonly PropertyData ChildrenProperty = RegisterProperty("Children", typeof(ObservableCollection<Person>), new ObservableCollection<Person>());
#endregion
#region Methods
/// <summary>
/// Validates the fields.
/// </summary>
protected override void ValidateFields()
{
if (Father == null)
{
SetFieldWarning(FatherProperty, "No father in this family");
}
if (Mother == null)
{
SetFieldWarning(MotherProperty, "No mother in this family");
}
}
/// <summary>
/// Validates the business rules.
/// </summary>
protected override void ValidateBusinessRules()
{
// No business rules yet
}
#endregion
}
}