有没有办法解决这个问题,还是我必须将GridViewColumn对齐到左侧或中央? 例如,我有一个列,显示文件大小,以MB为单位,我将它对齐到右边, 但如果我改变列的宽度,列中的文本将消失。
<ListView Name="myLV" SelectionMode="Single" ItemcontainerStyle="{DynamicResource lvis}" ItemSource="{Binding mySource}">
<ListView.View>
<GridView>
<GridViewColumn Header="Filename" local:MainWindow.SortName="Model.filename">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="0" Text="{Binding DisplayFilename}" VerticalAlignment="Center" Width="70" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Filesize" local:MainWindow.SortName="Model.FileSize">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="0" Text="{Binding DisplayFileSize}" VerticalAlignment="Center" TextAlignment="Right" Width="123" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
我的解决方案:
<ListView Name="myLV" SelectionMode="Single" ItemcontainerStyle="{DynamicResource lvis}" ItemSource="{Binding mySource}">
<ListView.View>
<GridView>
<GridViewColumn Header="Filename" local:MainWindow.SortName="Model.filename" width="Auto">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="0" Text="{Binding DisplayFilename}" VerticalAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Filesize" local:MainWindow.SortName="Model.FileSize" width="Auto">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="0" Text="{Binding DisplayFileSize}" VerticalAlignment="Center" TextAlignment="Right" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
GridViewColumn现在具有自动宽度,并删除了Textblock中的宽度。 现在文本不会消失。当空间没有空间时,它才开始消失。
答案 0 :(得分:0)