This project is read-only.

Does not react to model changes

Feb 2, 2013 at 7:11 PM

In all your samples you add all nodes before you set DataContext.
After some testing it seems it does not work to add nodes after the application has started.
I have testet this both by editing an existing sample by adding a button with the code:

private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        Node node = (Node) DataContext;
        node.Children.Add(new Node() { Name = "Testing,.."});
and by creating a new project with my own code. Is there some "Refresh" method i can call?
Feb 7, 2013 at 3:59 PM
Edited Feb 7, 2013 at 4:12 PM
I noticed the same problem.
In the "complex sample", I replaced the List<NodeBase> occurrences by ObservableCollection<NodeBase> .
Still, dynamically adding nodes after the creation of the tree does not produce any result in the view.

However, if I replace the TreeViewEx by the standard WPF TreeView , suddenly it works.

Question to the author: is this the normal behavior (i.e. TreeViewEx does not support view notification of changes in the ViewModel/DataContext) or are we doing something wrong?
Feb 8, 2013 at 2:40 PM
Hi and sorry for the late answer. I was quite busy.

I've tried this use case in the last release (1.1) and it worked seamlessly. Which Release/Build you are using?

To test ist, I've added a button to the simple sample and called this code in the click eventhandler:
first1.Children.Add(new Node { Name = "newElement" });
Feb 8, 2013 at 5:03 PM
Edited Feb 8, 2013 at 5:12 PM
Hi slompf,
thank you for your reply.

I downloaded the source 3 days ago and compiled the solution in the "Main" folder.

Right now, I checked it again.
In the simple sample in MainWindow.xaml I added this XAML code:
<Button DockPanel.Dock="Top" Click="Button_Click" Content="Add Node" />
and in MainWindow.xaml.cs this code:
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
            (DataContext as Node).Children.Add(new Node() { Name = "sdasd" });
and I don't see any reaction if I click the button.

And on a related note - I saw that you removed the "Selection Weirdness" item in the issue tracker.
Does that mean that the selection rectangle now scrolls the content if it extends outside the boundaries of the tree view? -- because that doesn't happen either in my case... so maybe I am indeed using the wrong build?
Feb 8, 2013 at 6:33 PM
Edited Feb 8, 2013 at 6:38 PM
Everyone is right :P

After some testing it seems it's possible to add child nodes after InitializeComponent(), but not root nodes.

firstNode.Children.Add(new Node { Name = "newElement" });
Does not work because it will add root nodes,

first1.Children.Add(new Node { Name = "newElement" });
(DataContext as Node).Children[0].Children.Add(new Node() { Name = "sdasd" });
works! because it will add child nodes.

I would still want the functionality to add root nodes, so ill wait for a fix.
Feb 11, 2013 at 8:36 AM
Edited Feb 11, 2013 at 9:15 AM
Nice find :)
slompf, would it be difficult/time-consuming to fix this?

Something minor that I also noticed is that if you add a child node to a node that previously didn't have any children, it doesn't receive a triangle to indicate that is has children which looks a bit strange, but this is just a display issue as it seems.
Feb 18, 2013 at 8:25 PM
I dont think so. I will have a look at it at the weekend. Thanks for testing this stuff!
Feb 20, 2013 at 8:38 AM
Cool, thx :)
Feb 22, 2013 at 2:59 PM
Edited Feb 22, 2013 at 3:00 PM
Should work with the last changeset (71241)
Feb 25, 2013 at 9:28 AM
Thanks a lot for your efforts.
I'll test it this week.
Mar 5, 2013 at 9:29 AM
Edited Mar 5, 2013 at 9:37 AM
Hi slompf,

adding new nodes at the root level works now, but I still noticed some strange behavior:

1. Adding a child node to a node that didn't have children before
does not add a triangle left to the node, as it should.
In the simple sample I added this event handler to the button at the top:
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
            (DataContext as Node).Children[0].Children[0].Children.Add(new Node() { Name = "asdasdas" });
On clicking the button, element11 receives a child, but doesn't receive a triangle left to it.

The opposite case doesn't work properly, either. If I change the event handler to the following:
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
            (DataContext as Node).Children[0].Children[2].Children.RemoveAt(0);
and click the button twice, element13 doesn't have any children left, but still has a triangle which is weird because there is nothing to expand.

2. In the simple sample, directly after running the app, do the following:
Expand the node element14.
After that, click on element14_7.
On my system, element14_7 is not properly selected now (border is set but the background is white). This also happens occasionally with other nodes.
What's going on there?
Mar 14, 2013 at 5:26 PM
I've added the issues to the bug tracker and will have a look on them.
Mar 27, 2013 at 9:27 AM
Seems you have fixed them?
I will test it in the next couple of days, thanks for your support.