Updates ItemsSource + Converter + Treeview

It's quite complicated, I hope I can make it clear enough for someone to help me. I have an object that allows me to call him a manager, a manager has a collection of people whom he manages, people all implement IPerson, but different types of people have different properties. I want to display this manager in the tree, and under the node manager I want to show all the projects that he manages that can be defined in the people he manages.

Thus, the plan is to use a converter to convert a person into a list of projects. Here is the XAML:

<HierarchicalDataTemplate DataType="{x:Type ui:Manager}">
   <TextBlock Text="{Binding Path=Name}"/>
    <HierarchicalDataTemplate.ItemTemplate>
        <DataTemplate>
                    <TextBlock Text="{Binding}"/>
        </DataTemplate>
    </HierarchicalDataTemplate.ItemTemplate>
    <HierarchicalDataTemplate.ItemsSource>
        <Binding Path="People">
            <Binding.Converter>
                <configUtil:ProjectListConverter/>
            </Binding.Converter>
        </Binding>
    </HierarchicalDataTemplate.ItemsSource>
</HierarchicalDataTemplate>

My Person INotifyPropertyChanged, , , INotifyCollectionChanged. , TreeView ItemsSource, .

, , TreeView . , , CollectionChanged Add . , CollectionChanged , , . , .

Add , IPerson:

public void Add(T item)
{
    list.Add(item);
    OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
}

- ?

?

"" , , .

+3

Source: https://habr.com/ru/post/1705739/


All Articles