Take the 2-minute tour ×

I have a TextBlock that I need to autosize to the width of a TreeView. The TreeView and the TextBlock are both contained in a StackPanel. The StackPanel is inside an Expander. The width of the TreeView should drive the width of the other objects and I need the height of the TextBlock to change to display the full text. All my efforts have resulted in the TextBlock driving the width. Thanks!

       <Expander IsEnabled="True" HorizontalAlignment="Right" Margin="0,8,8,53" x:Name="ExpanderBookMarks" Width="Auto" Foreground="#FF625B5B" ExpandDirection="Down" IsExpanded="True" Header="Bookmarks" Visibility="Hidden">

        <StackPanel Name ="StackPanelBookmark" Orientation="Vertical" Width="{wpf:Binding Path=Width, ElementName=trvBookmarks, Mode=Default}">

            <TreeView x:Name="trvBookmarks" ItemsSource="{Binding}" 
              ItemTemplateSelector="{StaticResource BookmarkTemplateSelector}" 
              TreeViewItem.Selected="HandleTreeViewItemClick" AllowDrop="True"/>

            <TextBlock x:Name="TextBlockBookmarkDiscription" TextWrapping="Wrap" Foreground="AntiqueWhite" Background="Transparent" Width="150">
                This is the discription area and needs to be very long because the end user can put 400 charectors in.                    


        <!--End of Dougs Treeview-->

share|improve this question

1 Answer 1

up vote 14 down vote accepted

Try this:

<TextBlock Width="{Binding ElementName=trvBookmarks,Path=ActualWidth}" ... />
share|improve this answer
+1 Legend. Thanks. –  ozczecho Feb 10 '10 at 12:39

Your Answer


