In the following code:
http://msdn.microsoft.com/en-us/library/ms754027.aspx
How to Bind IsExpanded to the MyData list of objects, where each object has the IsExpanded property?
<Expander IsExpanded={Binding Path=IsExpanded, Mode=TwoWay} />
This doesn’t work!
MyData is List<GroupNode>;
GroupNode is a class containing notify property changed property IsExpanded.
So, if I open one of the expander manually it should set the IsExpanded property to true of that MyData’s GroupNode.
It’s not very easy to do, because the
DataContextof theGroupItemis an instance ofCollectionViewGroup, and this class doesn’t have aIsExpandedproperty. You can however specify a converter in theGroupDescription, allowing you to return a custom value for the “name” of the group (theCollectionViewGroup.Nameproperty). This “name” can be anything; in your case, you need it to be a class that wraps the group name (e.g. grouping key) and has aIsExpandedproperty:Here’s an example:
And here’s the converter:
In XAML, just declare the grouping as follows:
And bind the
IsExpandedproperty like that: