WPF TableOfContents now expanded by default (100.7.1)

228
1
Jump to solution
04-16-2020 10:50 AM
JoeHershman
MVP Regular Contributor

In previous versions of the TableOfContents control the treeview was collapsed by default.  Now in 100.7.1 it is expanded by default.  We have a large number of layers and this is not acceptable to the users.

Current default:

I tried to see if I could close them when the TableOfContents is loaded by setting IsExpanded on the item to false, but this did not take

foreach (var item in TableOfContents.ItemsSource)
{
	if ( item is TocItem tocItem )
	{
		tocItem.IsExpanded = false;
	}
}

How can I get these to be collapsed when the TableOfContents initially

Morten Nielsen

Thanks

-Joe

0 Kudos
1 Solution

Accepted Solutions
JoeHershman
MVP Regular Contributor

I did find a solution that works by setting the IsExpanded when the item is added to the collection.  The following was added in the views code behind constructor

var collection = TableOfContents.ItemsSource as INotifyCollectionChanged;
if ( collection == null ) return;

collection.CollectionChanged += (sender, args) =>
{
	if ( args.NewItems == null ) return;
	foreach (var item in args.NewItems)
	{
		if ( item is TocItem tocItem )
		{
			tocItem.IsExpanded = false;
		}
	}
};‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

0 Kudos
1 Reply
JoeHershman
MVP Regular Contributor

I did find a solution that works by setting the IsExpanded when the item is added to the collection.  The following was added in the views code behind constructor

var collection = TableOfContents.ItemsSource as INotifyCollectionChanged;
if ( collection == null ) return;

collection.CollectionChanged += (sender, args) =>
{
	if ( args.NewItems == null ) return;
	foreach (var item in args.NewItems)
	{
		if ( item is TocItem tocItem )
		{
			tocItem.IsExpanded = false;
		}
	}
};‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos