2008-12-19 92 views
10

我有一個TextBlock,我需要自動調整到TreeView的寬度。 TreeViewTextBlock都包含在StackPanel中。 StackPanel位於Expander之內。 TreeView的寬度應驅動其他對象的寬度,我需要TextBlock的高度更改爲顯示全文。我所有的努力導致了TextBlock的寬度。謝謝!如何將文本塊設置爲自動調整爲TreeView的寬度?

 <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}" 
       Margin="0,0,0,0" 
       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.      
      </TextBlock> 

     </StackPanel> 

     <!--End of Dougs Treeview--> 

    </Expander> 

回答

18

試試這個:

<TextBlock Width="{Binding ElementName=trvBookmarks,Path=ActualWidth}" ... /> 
+0

+1傳奇。謝謝。 – ozczecho 2010-02-10 12:39:55

相關問題