我正在开发一个在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>
这就是现在发生的事情。漫长的&#34; aaaaa ......&#34;公司名称的最后一行中的值被切断。
答案 0 :(得分:0)
使用CellTemplate
:
<GridViewColumn Header="Company Name" Width="150">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding CompanyName}" TextWrapping="Wrap" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>