public class DeviceLocation : INotifyPropertyChanged
{
public Guid id{get;set ;}
public Guid? pid { get; set; }
public string text{get;set;}
public DeviceLocation Parent { get; set; }
public ObservableCollection<DeviceLocation> children{get;set;}
public event PropertyChangedEventHandler PropertyChanged;
private bool? isChecked;
public bool? IsChecked
{
get { return this.isChecked; }
set
{
if (this.isChecked != value)
{
this.isChecked = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("IsChecked"));
}
if (this.isChecked == true) // 如果节点被选中
{
if (this.children != null)
foreach (DeviceLocation dt in this.children)
dt.IsChecked = true;
if (this.Parent != null)
{
Boolean bExistUncheckedChildren = false;
foreach (DeviceLocation dt in this.Parent.children)
if (dt.IsChecked != true)
{
bExistUncheckedChildren = true;
break;
}
if (bExistUncheckedChildren)
this.Parent.IsChecked = null;
else
this.Parent.IsChecked = true;
}
}
else if (this.isChecked == false) // 如果节点未选中
{
if (this.children != null)
foreach (DeviceLocation dt in this.children)
dt.IsChecked = false;
if (this.Parent != null)
{
Boolean bExistCheckedChildren = false;
foreach (DeviceLocation dt in this.Parent.children)
if (dt.IsChecked != false)
{
bExistCheckedChildren = true;
break;
}
if (bExistCheckedChildren)
this.Parent.IsChecked = null;
else
this.Parent.IsChecked = false;
}
}
else
{
if (this.Parent != null)
this.Parent.IsChecked = null;
}
}
}
}
public DeviceLocation()
{
this.children = new ObservableCollection<DeviceLocation>();
}