Hi,
I have seen your examples where you have tree view inside a combobox. But the TreeItem being bound is actually a flat structure. I want to be able to achieve the same with a heirarchical structure, something like this
public
class
HeirarchicalTreeNode : INotifyPropertyChanged
{
private
bool
_isSelected;
public
HeirarchicalTreeNode()
{
Children =
new
List<HeirarchicalTreeNode>();
}
public
int
Id {
get
;
set
; }
public
string
Name {
get
;
set
; }
public
IList<HeirarchicalTreeNode> Children {
get
;
set
; }
public
bool
IsSelected
{
get
{
return
_isSelected; }
set
{
_isSelected = value;
PropertyChanged (
this
,
new
PropertyChangedEventArgs(
"IsSelected"
));
}
}
public
event
PropertyChangedEventHandler PropertyChanged;
public
bool
Equals(HeirarchicalTreeNode other)
{
if
(ReferenceEquals(
null
, other))
return
false
;
if
(ReferenceEquals(
this
, other))
return
true
;
return
other.Id == Id;
}
public
override
bool
Equals(
object
obj)
{
if
(ReferenceEquals(
null
, obj))
return
false
;
if
(ReferenceEquals(
this
, obj))
return
true
;
if
(obj.GetType() !=
typeof
(HeirarchicalTreeNode))
return
false
;
return
Equals((HeirarchicalTreeNode) obj);
}
public
override
int
GetHashCode()
{
return
Id;
}
}
I have done this in the attached sample. But when I select a leaf node the 1st time I get an exception. Also I want to configure it in such a way that I allow selection of leaf nodes only.
Thanks.