如何设置文本块自动调整大小以适应 TreeView 的宽度?
我有一个 TextBlock
,需要将其自动调整为 TreeView
的宽度。 TreeView
和 TextBlock
都包含在 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>
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}"
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这个:
Try this: