在不使用TextBox的情况下在GridView中包装文本?

时间:2017-10-24 13:01:17

标签: c# xml wpf

我正在开发一个在ListView中显示数据库内容的wpf窗口。它现在正常工作,但有一个问题 - 文本没有包装。我发现的大多数类似已解决的问题都建议使用带有Wrap选项的TextBox并将内容放在那里,但我想知道是否可以不使用它。这是我的代码:

<ListView Name="ListViewItem" ClipToBounds="True" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" SizeChanged="ListView_SizeChanged" Loaded="ListView_Loaded" TextOptions.TextHintingMode="Animated">
    <ListView.View>
        <GridView AllowsColumnReorder="False">
            <GridViewColumn Header="Company Name" DisplayMemberBinding="{Binding CompanyName}" Width="150"/>
            <GridViewColumn Header="Company Address" DisplayMemberBinding="{Binding CompanyAddress}" Width="350"/>
            <GridViewColumn Header="Company Email" DisplayMemberBinding="{Binding CompanyEmail}" Width="250"/>
            <GridViewColumn Header="Company Phone" DisplayMemberBinding="{Binding CompanyPhone}" Width="150"/>
            <GridViewColumn Header="Company NIP" DisplayMemberBinding="{Binding CompanyNIP}" Width="150"/>
            <GridViewColumn Header="Delete" Width="50">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <Button x:Name="DeleteGroup" Content="Delete" Click="DeleteGroup_Click" HorizontalContentAlignment="Center" VerticalContentAlignment="Stretch" BorderBrush="#FF9B5F5F" MinWidth="36" MinHeight="12" FontSize="8" HorizontalAlignment="Center" FontWeight="Bold">
                            <Button.OpacityMask>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="Black" Offset="0"/>
                                    <GradientStop Color="#FFBF2121" Offset="1"/>
                                </LinearGradientBrush>
                            </Button.OpacityMask>
                        </Button>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>

enter image description here

这就是现在发生的事情。漫长的&#34; aaaaa ......&#34;公司名称的最后一行中的值被切断。

1 个答案:

答案 0 :(得分:0)

使用CellTemplate

<GridViewColumn Header="Company Name" Width="150">
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding CompanyName}" TextWrapping="Wrap" />
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>