WPF Complex TreeView

545 views Asked by At

I am trying to create a TreeView structure with different object types in it. It is basically like the solution explorer of Visual Studio (Solution with Projects under it and under project there are Properties, References, Folders etc. with each having different context menu and TreeView gets updated when underlying structure gets changed ex: added new file.)

I have a project object. Which have Name, Path and List of other objects (input files, output files etc. which are custom classes).

I would like to display it as a structure on a TreeView with specific ContextMenues and double click events based on their type.

Project_Name
|-Inputs => ContextMenu => Add => opens dialog to add a new input file
|  |-Input1 => Double click will open a dialog to edit this input file
|  |-Input2
|  |-...
|-Outputs
   |-Output1 => Double click will open a dialog to edit this output file 
   |-Output2

Lets say I add a new input file by using context menu to open new input file dialog and once I am done I want the TreeView to be updated to show that input file as well.


UPDATE 1

I have created some HierarchicalDataTemplates

<Window.Resources>
    <HierarchicalDataTemplate DataType="{x:Type project:ETLProject}" ItemsSource="{Binding Path=InputDefinitions}">
        <TextBlock Text="Project"/>
    </HierarchicalDataTemplate>
    <HierarchicalDataTemplate DataType="{x:Type inputdef:InputDefinition}" ItemsSource="{Binding Path=Columns}">
        <TextBlock Text="{Binding Path=Name}"/>
    </HierarchicalDataTemplate>
    <DataTemplate DataType="{x:Type column:Column}">
        <TextBlock Text="{Binding Path=Name}"/>
    </DataTemplate>
</Window.Resources>

And I have the following TreeView

<TreeView Margin="5" Name="ProjectTreeView">
</TreeView>

When a project is loaded I set the DataContext of ProjectTreeView to the project object. However I do not see anything on the UI. When I change it to

<TreeView Margin="5" Name="ProjectTreeView" ItemsSource="{Binding Path=InputDefinitions}">
</TreeView>

I am able to see input definitions and columns as their children.

So how can I manage to make it project => input definitions => columns

0

There are 0 answers