Databinding TreeView with MVVM
I am trying to bind a view model to the tree view and I can't seem to get it to work. I have looked at all the examples and can't seem to find any working example using MVVM pattern. Here is the xaml
AllowDragDrop="True"
Name="CargoTree"
ItemContainerStyle="{StaticResource TreeViewItemStyle2}"
ItemTemplate="{StaticResource FiledataTemplate2}"
MultiColumnEnable="True" AllowMultiSelect="False">
DisplayMemberBinding="{Binding Path=Pieces}"
Header="Pieces"
Width="50"/>
DisplayMemberBinding="{Binding Path=PackageType}"
Header="PackageType"
Width="100"/>
DisplayMemberBinding="{Binding Path=ShortDesciption}"
Header="ShortDesciption"
Width="100" />
DisplayMemberBinding="{Binding Path=Weight}"
Header="Weight"
Width="50" />
DisplayMemberBinding="{Binding Path=Volume}"
Header="Volume"
Width="50" />
DisplayMemberBinding="{Binding Path=VolumeWeight}"
Header="VolumeWeight"
Width="50" />
DisplayMemberBinding="{Binding Path=Dimensions}"
Header="Dimensions"
Width="100" />
DisplayMemberBinding="{Binding Path=Quantity}"
Header="Quantity"
Width="50" />
In my app.xaml I have
Margin="2,0" />
And my view model looks like this
public class ItemViewModel
{
bool _isExpanded;
bool _isSelected;
public string Pieces { get; set; }
public string PackageType { get; set; }
public string ShortDesciption { get; set; }
public string Weight { get; set; }
public string Volume { get; set; }
public string VolumeWeight { get; set; }
public string Dimensions { get; set; }
public string Quantity { get; set; }
public ObservableCollection Children { get; set; }
public bool IsExpanded
{
get { return _isExpanded; }
set
{
if (value != _isExpanded)
{
_isExpanded = value;
this.OnPropertyChanged("IsExpanded");
}
// Expand all the way up to the root.
if (_isExpanded && _parent != null)
_parent.IsExpanded = true;
}
}
public ItemViewModel(string name)
{
PackageType = name;
Children = new ObservableCollection();
}
public void AddChild(string name)
{
Children.Add(new ItemViewModel(name));
}
public bool IsSelected
{
get { return _isSelected; }
set
{
if (value != _isSelected)
{
_isSelected = value;
this.OnPropertyChanged("IsSelected");
}
}
}
private ItemViewModel _parent;
public ItemViewModel Parent { get { return _parent; } }
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
Name="CargoTree"
ItemContainerStyle="{StaticResource TreeViewItemStyle2}"
ItemTemplate="{StaticResource FiledataTemplate2}"
MultiColumnEnable="True" AllowMultiSelect="False">
Header="Pieces"
Width="50"/>
Header="PackageType"
Width="100"/>
Header="ShortDesciption"
Width="100" />
Header="Weight"
Width="50" />
Header="Volume"
Width="50" />
Header="VolumeWeight"
Width="50" />
Header="Dimensions"
Width="100" />
Header="Quantity"
Width="50" />
In my app.xaml I have
And my view model looks like this
public class ItemViewModel
{
bool _isExpanded;
bool _isSelected;
public string Pieces { get; set; }
public string PackageType { get; set; }
public string ShortDesciption { get; set; }
public string Weight { get; set; }
public string Volume { get; set; }
public string VolumeWeight { get; set; }
public string Dimensions { get; set; }
public string Quantity { get; set; }
public ObservableCollection
public bool IsExpanded
{
get { return _isExpanded; }
set
{
if (value != _isExpanded)
{
_isExpanded = value;
this.OnPropertyChanged("IsExpanded");
}
// Expand all the way up to the root.
if (_isExpanded && _parent != null)
_parent.IsExpanded = true;
}
}
public ItemViewModel(string name)
{
PackageType = name;
Children = new ObservableCollection
}
public void AddChild(string name)
{
Children.Add(new ItemViewModel(name));
}
public bool IsSelected
{
get { return _isSelected; }
set
{
if (value != _isSelected)
{
_isSelected = value;
this.OnPropertyChanged("IsSelected");
}
}
}
private ItemViewModel _parent;
public ItemViewModel Parent { get { return _parent; } }
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
SIGN IN To post a reply.
3 Replies
MK
Mayavel K
Syncfusion Team
September 29, 2010 01:56 PM UTC
Hi Rafel,
We are able to reproduce the binding issue with MulticolumnTreeViewAdv and logged an issue report internally. However we can't provide the updated assemblies through forum. Since please create the DirectTrac incident for this issue so that we can provide a updated assemblies.
Please let us know if you have any queries.
Regards,
Mayavel k
We are able to reproduce the binding issue with MulticolumnTreeViewAdv and logged an issue report internally. However we can't provide the updated assemblies through forum. Since please create the DirectTrac incident for this issue so that we can provide a updated assemblies.
Please let us know if you have any queries.
Regards,
Mayavel k
GB
Gautier Boder
December 28, 2010 09:23 AM UTC
Hello,
Was this new assembly published for all users into the current distribution of Essential Studio? Or this issue is still alive in the widely distributed version?
Thanks for your support
Gautier Boder
Was this new assembly published for all users into the current distribution of Essential Studio? Or this issue is still alive in the widely distributed version?
Thanks for your support
Gautier Boder
MM
Mageshyadav M
Syncfusion Team
January 5, 2011 06:46 PM UTC
Hi Gautier,
Sorry for the delay in getting back to you.
The issue is not in our latest version 8.4.0.10.
Please find the sample demonstrating MVVM sample with TreeViewColumns below,
Bind to Self-Referencing Table Demo2042358590.zip
Please let us know if you have any queries.
Regards,
Mageshyadav.M
Sorry for the delay in getting back to you.
The issue is not in our latest version 8.4.0.10.
Please find the sample demonstrating MVVM sample with TreeViewColumns below,
Bind to Self-Referencing Table Demo2042358590.zip
Please let us know if you have any queries.
Regards,
Mageshyadav.M
SIGN IN To post a reply.
- 3 Replies
- 4 Participants
-
RS Rafael Soto
- Sep 23, 2010 03:47 AM UTC
- Jan 5, 2011 06:46 PM UTC