This project is read-only.

A problem with control widht and height?

Aug 1, 2008 at 10:10 AM
Edited Aug 4, 2008 at 10:42 AM
I think there is a problem with the treeview width and height when you do not assign them directly. For example, if you use it inside a grid.
Well, I can’t say I understand how the code works for now, but I think the problem is in the UpdateVisualState() function.

1) You use this.ElementContainer.Width = base.Width – 2.0 and I think it must be base.ActualWidth.
2) It seems that silverlight does measurement and layout asynchronously and you must set the width and height inside a Dispatcher.BeginInvoke call. ( I read it here )
The function will result like this
protected override void UpdateVisualState()
    if (base.ElementRoot != null)
          this.ElementContainer.Width = base.ActualWidth - 2.0;
          this.ElementContainer.Height = base.ActualHeight - 2.0;
       this.ElementContainer.Background = this._backgroundBrush;

3) For the last you have to assing the LayoutUpdated event for it to change dinamically (for example with a splitter in the grid).

In the constructor add
 this.LayoutUpdated += new EventHandler(TreeView_LayoutUpdated);
and in the implementation of TreeView_LayoutUpdated simply call UpdateVisualState.

Well, I repeat that I’m just beginning to learn how controls work in Silverlight and how your control works so maybe there are better solutions but I thought it could help!
And thanks again for your work!

Aug 1, 2008 at 2:35 PM

Tamir is usually right ;) I'll check it and if there is an issue and your solution solves it, I'll add it to the project.

Oct 10, 2008 at 10:54 PM
Edited Oct 10, 2008 at 10:55 PM
Hello, I'm using the 10/3 release and I can't get the tree to have a width of the largest tree view node.  Is the current implementation of the tree constrained to having a fixed width? $0Thanks!$0$0Cyrus$0
Oct 11, 2008 at 6:03 AM
Hi Cyrus,

Could you please provide me with a repro? I'm not aware of the problem, so you repro will help me to solve it.

Oct 18, 2008 at 9:30 PM
Edited Oct 18, 2008 at 9:43 PM
Hi Alex, It is the same problem that daniCE mentions above. If you leave out the width of the treeview, it doesn't expand to the width of the largest child.  For example, there is no width or height specified in the following:               <local:TreeView x:Name="foldersTree" EnableCheckboxes="False" EnableDragAndDrop="False"                                   SelectionChanged="foldersTree_SelectionChanged"                                    Populate="foldersTree_Populate"                                   MultiSelect="False"                                    Margin="5"                                     BorderThickness="0" > What happens is the tree width is like 10 pixels even though the actual width should be much wider.  Also, as an fyi, I am dynamically populating the tree.  I just need the tree...I don't need the border, scrolling, fixed width, etc....I am putting this in a grid and will have the grid handle all of that for me.  Thanks for any help, this treeview control is great...