【问题标题】:How Do You Set a Textblock to Autosize to the Width of a TreeView?如何将文本块设置为自动调整为 TreeView 的宽度?
【发布时间】:2008-12-19 16:54:59
【问题描述】:

我有一个TextBlock,需要自动调整为TreeView 的宽度。 TreeViewTextBlock 都包含在 StackPanel 中。 StackPanelExpander 内。 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>

【问题讨论】:

    标签: wpf textblock autosize


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 2010-11-23
      • 1970-01-01
      • 1970-01-01
      • 2017-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-23
      相关资源
      最近更新 更多