property binding of TreeViewEx Control to LocalControl not working fine in one case

Aug 10, 2012 at 1:45 PM

Hi,

We are facing a problem with TreeViewEx control.

In our application, we are binding an ObservableCollection with TreeViewEx ItemSource . Observable collection is collection of objects of our class which is having some properties binded to TreeViewExItem properties.Every item in observable collection is a TreeViewExItem.

Now process goes in this way:- when we click on the root element of treeview control.We add the children of this in Observable collection.Code sample for this is as shown below:-

foreach (var childEntityNode in orderedChildEntityNodes)

{

     observableHierarchy.Children.Add(childEntityNode);

}

 

After this, we do other operation also & set some property of child nodes. When all the operation gets complete then it fires the treeViewEx control’s OnInitialize process for each child, while it is expected to fire at once on the time of adding children in ObservableHierarchy.

Because of this , the property binding of our class with treeviewEx control doesn’t work properly.

In other scenario when we add all the children’s & do not set any property at that time. After when the initialization of all children is done , we set property of that nodes then In that case all bindings with control works fine.

Can you please , Help out in this.

Coordinator
Aug 11, 2012 at 12:02 PM

Hi,

so probably your problem occures because someone reinitializes the properties. I dont know who or when. Maybe it is done in the initialization routines of the base classes. I’m not sure.
But in order to help you best, I have to ask why you do it that way? The normal way would be to bind a Observable collection of viewmodels to the ItemsSource. Thy would have to implement INotifyPropertyChanged and apply a DataTemplate to make them look like you want. If you would do so, the TreeViewExItems would be initalized by the TreeViewEx and you would not have any of the problems you described.
If you can not go the way I suggested, you might provide some sample application, so I can debug the problem.
Regards
Aug 17, 2012 at 6:39 AM
Hi,
Thanks for ur concern. I am looking into this. As soon as i get the root cause of this problem i will inform u. Else i will send u the sample application.
Thanks
Saurabh Jain

On 17 August 2012 03:55, slompf <notifications@codeplex.com> wrote:

From: slompf

Hi,

so probably your problem occures because someone reinitializes the properties. I dont know who or when. Maybe it is done in the initialization routines of the base classes. I’m not sure.
But in order to help you best, I have to ask why you do it that way? The normal way would be to bind a Observable collection of viewmodels to the ItemsSource. Thy would have to implement INotifyPropertyChanged and apply a DataTemplate to make them look like you want. If you would do so, the TreeViewExItems would be initalized by the TreeViewEx and you would not have any of the problems you described.
If you can not go the way I suggested, you might provide some sample application, so I can debug the problem.
Regards

Read the full discussion online.

To add a post to this discussion, reply to this email (treeviewex@discussions.codeplex.com)

To start a new discussion for this project, email treeviewex@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com




--
With Regards:-
Saurabh Jain
GE Energy, Mumbai

Sep 15, 2012 at 10:03 AM

Saurabh,

the Initialized event of FrameworkElements is fired when the element has been fully initialized by the framework, which happens after it has been added to the UI, IIRC. Since you are adding your child controls (and no data items!) directly to that collection, they are only later added to the actual control in your window and then (asynchronously) initialised. That is after your method that adds the controls and sets some properties on them completes.

I really think that you shouldn't use the TreeViewExItem directly in the Children collection. That collection is meant to hold data items and the TreeViewEx control creates a TreeViewExItem for each of them itself. (At least this is the only way I've learned to use a TreeView in WPF, I don't know anything else about this other than it must be complicated as hell...)

This is the article that teached things to me: http://www.codeproject.com/Articles/26288/Simplifying-the-WPF-TreeView-by-Using-the-ViewMode