My XAML is very simple:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<TextBlock FontSize="55" HorizontalAlignment="Center"
VerticalAlignment="Center" TextWrapping="Wrap">Left side</TextBlock>
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Center" />
<TreeView Grid.Column="2" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
<TreeViewItem>
<TreeViewItem.Header>
<TextBlock Text="The full string"
TextTrimming="CharacterEllipsis"/>
</TreeViewItem.Header>
<TreeViewItem>
<TreeViewItem.Header>
<TextBlock Text="The full string"/>
</TreeViewItem.Header>
</TreeViewItem>
</TreeViewItem>
</TreeView>
<Border BorderBrush="Green" BorderThickness="5" CornerRadius="5" Grid.Column="3" />
</Grid>
What I have is:
and it is not correct for me:
And what behavior I want is:
How can I use TextTrimming
property of TextBlock
placed in TreeViewItem
?
答案 0 :(得分:1)
您需要修改TreeViewItem
的样式,因为内容未被拉伸。
请参阅
中的样式示例和问题说明https://leecampbell.com/2009/01/14/horizontal-stretch-on-treeviewitems/
只需将链接中的样式应用到TreeView
<TreeView>
<TreeView.Resources>
<!--paste the style from the link here-->
</TreeView.Resources>
很抱歉没有发布样式,但我没有完成格式化。