ListView的一部分被截止

时间:2017-03-27 10:20:19

标签: c# wpf pdf

我使用此代码将均匀宽度分配给所有列,但它仍然通过其父级,生成水平滚动

private void listView_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        var newWidth = listView.ActualWidth / gridView.Columns.Count;
        foreach (var column in gridView.Columns)
        {
            column.Width = newWidth;
        }
    }

WPF List View

因此,当我将其转换为PDF文件时,会产生如下内容:

PDF List View

我已经将列表视图的宽度调整为与A4纸相同。哦,纸张是字母大小,这就是为什么右边有一个白色的间距

public void CreateMyWPFControlReport()
    {

        FixedDocument fixedDoc = new FixedDocument();
        PageContent pageContent = new PageContent();
        FixedPage fixedPage = new FixedPage();
        someGrid.Children.Remove(listView);
        listView.Width = 96 * 8.267;
        //Create first page of document
        fixedPage.Children.Add(listView);
        ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage);
        fixedDoc.Pages.Add(pageContent);
        //Create any other required pages here


        MemoryStream lMemoryStream = new MemoryStream();
        {
            Package package = Package.Open(lMemoryStream, FileMode.Create);
            XpsDocument xpsd = new XpsDocument(package);
            XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd);
            xw.Write(fixedDoc);
            xpsd.Close();
            package.Close();
        }

        var pdfXpsDoc = PdfSharp.Xps.XpsModel.XpsDocument.Open(lMemoryStream);
        try
        {
            PdfSharp.Xps.XpsConverter.Convert(pdfXpsDoc, @"C:/nye/affaf.pdf", 0);
        }
        catch (IOException ex)
        {
            MessageBox.Show("File is open, please close first");
        }
    }

导致这种行为的原因是什么?虽然我可以一点一点地减小宽度,但这会耗费一些时间。或者我需要这样做吗?

1 个答案:

答案 0 :(得分:1)

要删除水平滚动,请尝试在XAML中设置ListView的$http.post(BASE_URL, formData, { withCredentials: true, transformRequest: angular.identity, params: {'context': context}, uploadEventHandlers: { progress: function(event) {//Add whatever you want to do} } }) (附加属性)。

ScrollViewer.HorizontalScrollBarVisibility

要将均匀宽度分布到ListView的所有GridViewColumns,您可以使用值转换器。每当需要重新评估GridViewColumn的宽度时(如调整应用程序大小后),WPF将自动调用转换器的Convert()方法。

 <ListView x:Name="listView" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ... >
    ...       
 </ListView>

要在XAML中使用此值转换器,请将其添加为资源。传递给转换器的public class ListViewEvenColumnWidthConverter : IValueConverter { public int ColumnCount { get; set; } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) return 0; double width = (double)value; if (width == 0) return 0; return width / ColumnCount; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } Convert()方法,是整个listview的宽度。我们希望返回该值除以列数。例如,有四个GridViewColumns;

value