ListView列标题 - 在最后一个标题之后有一个白色间隙

时间:2018-01-25 17:23:19

标签: wpf xaml listview templates

用文字解释很难。 我为ListView做了一个类似于这样的样式和模板:https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/listview-styles-and-templates 我原来是这样的: enter image description here

如您所见,在标题中,最后一列之后有一个奇怪的白色间隙。我怎样才能解决这个问题?

2 个答案:

答案 0 :(得分:0)

通常你可以像width = "*"那样在WPF中设置宽度,它会自动填充空白区间。但是,据我所知,ListView无法做到。您可以使用固定宽度或将其设置为自动。如果我是你,我会切换到DataGrid

如果您真的想坚持ListView,我建议您自定义IValueConverter。您可Bind Width GridViewColumn ActualWidthListView public class StarWidthConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { ListView listview = value as ListView; double width = listview.Width; GridView gv = listview.View as GridView; for (int i = 0; i < gv.Columns.Count; i++) { if (!Double.IsNaN(gv.Columns[i].Width)) width -= gv.Columns[i].Width; } return width -5;// this is to take care of margin/padding } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; } }

protected $table = 'admins';

答案 1 :(得分:0)

也许你的ListView在Grid内,所以Horizo​​ntalAlignment的默认值是Stretch,ListView会自动生成一个空白列来填充所有可用空间,以避免你可以将ListView放入StackPanel然后将Orientation设置为“Horizo​​ntal”或明确设置ListView的Horizo​​ntalAlignment值。像这样的东西

<ListBox HorizontalAlignment="Left"/>