I have a RadTreeListView and I want to display the image on the row where no child exists. Remaining nodes has children so they appears with Expand/Collapse sign. I read up on HierarchicalDataTemplates, but not sure how to use it on RadTreeListView. Any suggestions?
XAML :
<UserControl x:Class="ExpandCollapseImage.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:telerikSdk="http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<telerikSdk:RadTreeListView x:Name="radTreeListView" AutoGenerateColumns="False" >
<telerikSdk:RadTreeListView.ChildTableDefinitions>
<telerikSdk:TreeListViewTableDefinition ItemsSource="{Binding Items}" />
</telerikSdk:RadTreeListView.ChildTableDefinitions>
<telerikSdk:RadTreeListView.Columns>
<telerikSdk:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Name" />
<telerikSdk:GridViewDataColumn DataMemberBinding="{Binding Count}" Header="Count" />
</telerikSdk:RadTreeListView.Columns>
</telerikSdk:RadTreeListView>
</Grid>
</UserControl>
XAML.CS :
using System.Windows.Controls;
using System.Collections.ObjectModel;
namespace ExpandCollapseImage
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
BindData();
}
public class WarehouseItem
{
public WarehouseItem(string name, int count, string imageUri)
{
this.Name = name;
this.Count = count;
this.Items = new ObservableCollection<WarehouseItem>();
this.Photo = imageUri;
}
public string Name { get; set; }
public ObservableCollection<WarehouseItem> Items { get; set; }
public int Count { get; set; }
public string Photo { get; set; }
}
public class WarehouseService
{
public static ObservableCollection<WarehouseItem> GetWarehouseData()
{
//System.Windows.Controls.Image img = new System.Windows.Controls.Image();
////img.Cursor = Cursors.Hand;
//img.Source = new BitmapImage(new Uri("/Images/Add.png", UriKind.RelativeOrAbsolute));
ObservableCollection<WarehouseItem> data = new ObservableCollection<WarehouseItem>();
WarehouseItem drinks = new WarehouseItem("Drinks", 35, string.Empty);
drinks.Items.Add(new WarehouseItem("Water", 10, string.Empty));
WarehouseItem tea = new WarehouseItem("Tea", 20, string.Empty);
tea.Items.Add(new WarehouseItem("Black", 10, string.Empty));
tea.Items.Add(new WarehouseItem("Green", 10, string.Empty));
drinks.Items.Add(tea);
drinks.Items.Add(new WarehouseItem("Coffee", 5, string.Empty));
data.Add(drinks);
WarehouseItem vegetables = new WarehouseItem("Vegeatbles", 75, string.Empty);
vegetables.Items.Add(new WarehouseItem("Tomato", 40, string.Empty));
vegetables.Items.Add(new WarehouseItem("Carrot", 25, string.Empty));
vegetables.Items.Add(new WarehouseItem("Onion", 10, string.Empty));
data.Add(vegetables);
WarehouseItem fruits = new WarehouseItem("Fruits", 55, string.Empty);
fruits.Items.Add(new WarehouseItem("Cherry", 30, string.Empty));
fruits.Items.Add(new WarehouseItem("Apple", 20, string.Empty));
fruits.Items.Add(new WarehouseItem("Melon", 5, string.Empty));
data.Add(fruits);
WarehouseItem Soda = new WarehouseItem("Soda", 10, "/Images/Add.png");
data.Add(Soda);
return data;
}
}
public void BindData()
{
this.radTreeListView.ItemsSource = WarehouseService.GetWarehouseData();
}
}
}
DESIRED OUTPUT :