TextTrimming property of TextBlock placed in TreeViewItem using GridSplitter

时间:2016-04-15 11:12:41

标签: c# wpf xaml gridsplitter texttrimming

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:

enter image description here

and it is not correct for me:

enter image description here

And what behavior I want is:

enter image description here

How can I use TextTrimming property of TextBlock placed in TreeViewItem?

1 个答案:

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

很抱歉没有发布样式,但我没有完成格式化。