Hi Team,
I need to show Icons in the Tree View Item. My Requirement is as below.
I have a class Materials
public class Materials
{
Public Int MaterialID{get;set;}
public string MaterialName{get;set:}
public observablecollection<Materials> submaterials {get;set;}
}
I have 5 Different Material ID's Based on the Material ID I need to display an ICON next to MaterialName, to identify the material based on the Icon.
In My XAML i did some thing like below which is static
<ig:NodeLayout.ItemTemplate>
<StackPanel Orientation="Horizontal"> <Image Source="..\Images\folder_star.png"/> <TextBlock Text="{Binding Data.MaterialName}" FontWeight="Bold" /></stackPanel>
</ig:NodeLayout.ItemTemplate>
I need to change the Source based on the Material ID.
Do you have any Examples of this Kind.
Hi,
You are very welcome. Glad I could help.
Thanks Marianne
This solution works as per our requirement.
I would suggest that you use a converter and bind to the image source. You could then either add a property to your data for the name of the image or code in your converter to assign an image name based on some other value in your data.
<ig:NodeLayout.CollapsedIconTemplate>
<DataTemplate>
<Image Source="{Binding Converter={StaticResource getImagePathConverter}}" />
</DataTemplate>
</ig:NodeLayout.CollapsedIconTemplate>
Here’s an example of a converter based on a property in my data.
public class GetImagePathConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
BitmapImage img = new BitmapImage();
if (value is XamDataTreeNodeDataContext)
ReportSet rSet = (((XamDataTreeNodeDataContext) value).Data) as ReportSet;
if (rSet != null)
string fileName = ((String)rSet.Ico).TrimStart(@" \/".ToCharArray()).Replace(@"\", "/");
string path = "../Icons/" + fileName;
img = new BitmapImage();
img.BeginInit();
img.UriSource = new Uri(path, UriKind.Relative);
img.EndInit();
return img;
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
throw new NotImplementedException();
Please let me know if you have any questions.
Any Suggestions on the the Above Scenario