我在WPF中使用ListView . 为了扩展最后一列宽度,我使用的方法类似于:
How to resize a certain control based on Window size in WPF?
当我实现附加的代码时,总是出现一个水平滚动条,所以我理解ListView的内容比控件大 . 可以隐藏滚动条的可见性,但它无法解决问题 .
public class WidthConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
double listViewWidth;
double otherColumnsTotalWidth = 0;
double.TryParse(values[0].ToString(), out listViewWidth);
var arrayOfColumns = values[1] as IList<GridViewColumn>;
for (int i = 0; i < arrayOfColumns.Count - 1; i++)
{
otherColumnsTotalWidth += arrayOfColumns[i].Width;
}
return (listViewWidth - otherColumnsTotalWidth) < 0 ? 0 : (listViewWidth - otherColumnsTotalWidth);
}
public object[] ConvertBack(object value, Type[] targetTypes,
object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
和XAML:
<GridViewColumn Header="Text" DisplayMemberBinding="{Binding Text1}">
<GridViewColumn.Width>
<MultiBinding Converter="{StaticResource LastColumnWidtConverter}">
<Binding Path="ActualWidth" RelativeSource="{RelativeSource AncestorType=ListView}"/>
<Binding Path="View.Columns" RelativeSource="{RelativeSource AncestorType=ListView}"/>
</MultiBinding>
</GridViewColumn.Width>
-
为什么出现HorizontalScrollBar,即使内容较小?这里基本上列的宽度是计数并从整个宽度中减去 . 因此,剩余宽度应完全适合填充剩余空间 .
-
查看右侧的最后一列(应该扩展),列 Headers 中会出现一个分隔符 . 为什么会这样?
我怎么处理这个?