ObservableCollection is not updating Multibinding in C# WPF
- by Decept
I have a TreeView that creates all its items from databound ObservableCollections. I have a hierarchy of GameNode objects, each object has two ObservableCollections. One collections has EntityAttrib objects and the other have GameNode objects. You could say that the GameNode object represents folders and EntityAttrib represents files. To display both attrib and GameNodes in the same TreeView I use Multibinding.
This all works fine in startup, but when I add a new GameNode somewhere in the hierarchy the TreeView is not updated. I set a breakpoint in my converter method but it's not called when adding a new GameNode. It seems that the ObservableCollection is not notifying the MultiBinding of the change. If I comment out the MultiBinding and only bind the GameNode collection it works as expected.
XAML:
<HierarchicalDataTemplate DataType="{x:Type local:GameNode}">
<HierarchicalDataTemplate.ItemsSource>
<MultiBinding Converter="{StaticResource combineConverter}">
<Binding Path="Attributes" />
<Binding Path="ChildNodes" />
</MultiBinding>
</HierarchicalDataTemplate.ItemsSource>
<TextBlock Text="{Binding Path=Name}" ContextMenu="{StaticResource EntityCtxMenu}"/>
</HierarchicalDataTemplate>
C#:
public class GameNode
{
string mName;
public string Name { get { return mName; } set { mName = value; } }
GameNodeList mChildNodes = new GameNodeList();
public GameNodeList ChildNodes { get { return mChildNodes; } set { mChildNodes = value; } }
ObservableCollection<EntityAttrib> mAttributes = new ObservableCollection<EntityAttrib>();
public ObservableCollection<EntityAttrib> Attributes { get { return mAttributes; } set { mAttributes = value; } }
}
GameNodeList is a subclassed ObservableCollection