We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Tree view databinding MVVM

Thread ID:

Created:

Updated:

Platform:

Replies:

96622 Sep 23,2010 03:44 AM UTC Sep 30,2010 04:33 AM UTC ASP.NET Web Forms (Classic) 2
loading
Tags: Tools
Rafael Soto
Asked On September 23, 2010 03:44 AM UTC

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
}




Rafael Soto
Replied On September 23, 2010 03:48 AM UTC

Sorry posted in the wrong forum, this should of gone in the WPF forum. I have posted there.


Mageshyadav M [Syncfusion]
Replied On September 30, 2010 04:33 AM UTC

Hi Rafael,

Your query has been already answered through Forum

http://www.syncfusion.com/support/forums/general/96623

Please refer to forum 96623.

Regards,
Mageshyadav.M


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;