如何将Textblock设置为自动调整为TreeView的宽度?

时间:2008-12-19 16:54:59

标签: wpf textblock autosize

我有TextBlock我需要自动调整到TreeView的宽度。 TreeViewTextBlock都包含在StackPanel中。 StackPanel位于Expander内。 TreeView的宽度应该驱动其他对象的宽度,我需要更改TextBlock的高度以显示全文。我的所有努力都导致了TextBlock驱动宽度。谢谢!

       <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>

1 个答案:

答案 0 :(得分:18)

试试这个:

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