Hello,
I made a sample MVVM project where I have a ViewModel for my nodes:
I have bound the IsExpanded property to a property of my ViewModel like this:
And I was a little bit disappointed when I saw that if you add a node with a ViewModel where the IsExpanded property is already set to True, the node will be first collapsed than expanded.
If you have a lot of nodes and you refresh the state of the nodes frequently, it's really annoying.
Best regards,
I made a sample MVVM project where I have a ViewModel for my nodes:
public
class
WarehouseItem : INotifyPropertyChanged
{
public
event
PropertyChangedEventHandler PropertyChanged;
private
bool
isExpanded;
private
string
name;
private
IList<WarehouseItem> m_items;
public
WarehouseItem(
string
name,
int
count,
bool
isExpanded =
true
)
{
this
.Name = name;
this
.IsExpanded = isExpanded;
this
.Items = (from l_i
in
System.Linq.Enumerable.Range(0, count)
select
new
WarehouseItem(
"SubItem"
+ (l_i + 1), 0,
false
)).ToList();
}
public
string
Name
{
get
{
return
this
.name;
}
set
{
if
(value !=
this
.name)
{
this
.name = value;
this
.OnPropertyChanged(
"Name"
);
}
}
}
public
bool
IsExpanded
{
get
{
return
this
.isExpanded;
}
set
{
if
(value !=
this
.isExpanded)
{
this
.isExpanded = value;
this
.OnPropertyChanged(
"IsExpanded"
);
}
}
}
public
IList<WarehouseItem> Items
{
get
{
return
this
.m_items; }
set
{
if
(
this
.m_items != value)
{
this
.m_items = value;
this
.OnPropertyChanged(
"Items"
);
}
}
}
protected
virtual
void
OnPropertyChanged(PropertyChangedEventArgs args)
{
PropertyChangedEventHandler handler =
this
.PropertyChanged;
if
(handler !=
null
)
{
handler(
this
, args);
}
}
private
void
OnPropertyChanged(
string
propertyName)
{
this
.OnPropertyChanged(
new
PropertyChangedEventArgs(propertyName));
}
}
I have bound the IsExpanded property to a property of my ViewModel like this:
<
telerik:RadTreeListView
IsExpandedBinding
=
"{Binding IsExpanded, Mode=TwoWay}"
AutoGenerateColumns
=
"False"
ItemsSource
=
"{Binding}"
>
<
telerik:RadTreeListView.ChildTableDefinitions
>
<
telerik:TreeListViewTableDefinition
ItemsSource
=
"{Binding Items}"
/>
</
telerik:RadTreeListView.ChildTableDefinitions
>
<
telerik:RadTreeListView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Name}"
Header
=
"Name"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding IsExpanded}"
Header
=
"Is Expanded"
/>
</
telerik:RadTreeListView.Columns
>
</
telerik:RadTreeListView
>
And I was a little bit disappointed when I saw that if you add a node with a ViewModel where the IsExpanded property is already set to True, the node will be first collapsed than expanded.
If you have a lot of nodes and you refresh the state of the nodes frequently, it's really annoying.
Best regards,