I know many threads have been opened and I all read those to help better understand how to use the treeview and still I'm unable to render the treeview properly if not at all.
I only succeed to render one level of the tree and I have 3 level.
My question is : What is wrong with my code below ?
Level 1 class :
public class ProductModel
{
public decimal? id { get; set; }
public string product_pn { get; set; }
public string product_desc { get; set; }
public BoardTypesModel product_board_type { get; set; }
}
Level 2 class :
public class BoardTypesModel
{
public decimal? id { get; set; }
public string board_type { get; set; }
public string product_family { get; set; }
public float board_length_inches { get; set; }
public List<PulseCurrentModel> lsPulseCurrents { get; set; }
}
Level 3 class :
public class PulseCurrentModel
{
public decimal? id { get; set; }
public float voltage_setpoint { get; set; }
public float nominal_current { get; set; }
public float current_tolerance { get; set; }
public float nominal_power { get; set; }
public float power_tolerance { get; set; }
public string test_type { get; set; }
public int order_priority { get; set; }
public decimal? board_type_id { get; set; }
}
In my viewmodel, I have the following line of interest which is initialized properly on modelview load and it works fine :
private ObservableCollection<Models.ProductModel> _ocProducts;
public ObservableCollection<Models.ProductModel> ocProducts
{
get { return _ocProducts; }
set
{
_ocProducts = value;
RaisePropertyChangedEvent("ocProducts");
}
}
Finally, my xaml treeview code to render this observable collection :
<TreeView DockPanel.Dock="Top" ItemsSource="{Binding ocProducts}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding product_board_type}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding product_pn}" />
<TextBlock Text=" - " Foreground="Blue" />
<TextBlock Text="{Binding product_desc}" Foreground="Blue" />
</StackPanel>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding lsPulseCurrents}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding board_type}" />
<TextBlock Text=" (" Foreground="Green" />
<TextBlock Text="{Binding board_length_inches}" Foreground="Green" />
<TextBlock Text=" inches) " Foreground="Green" />
<TextBlock Text="{Binding product_family}" Foreground="Green" />
</StackPanel>
<!--<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Voltage : "></TextBlock>
<TextBlock Text="{Binding voltage_setpoint}" />
</StackPanel>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>-->
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>