Print long listview on printVisual C# WPF

I created a print for my UserControl. this is my ListView, this list can have data 100+

<ListView Grid.Row="2" Name="LstProduk" HorizontalContentAlignment="Stretch" Padding="0" BorderThickness="0" Margin="-1 , -0.75">
    <ListView.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="Margin" Value="0"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="MinHeight" Value="20"></Setter>
        </Style>
    </ListView.ItemContainerStyle>
                          
    <ListView.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition MinHeight="20"></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="37"></ColumnDefinition>
                    <ColumnDefinition Width="56"></ColumnDefinition>
                    <ColumnDefinition Width="223"></ColumnDefinition>
                    <ColumnDefinition Width="148"></ColumnDefinition>
                    <ColumnDefinition Width="148"></ColumnDefinition>
                    <ColumnDefinition Width="148"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Border Grid.Column="0" BorderThickness="0.75" BorderBrush="Black">
                    <TextBlock Text="{Binding no}" VerticalAlignment="Center" FontSize="14" Margin="5 0" TextWrapping="Wrap"></TextBlock>
                </Border>
                <Border  Grid.Column="1"  BorderThickness="0.75" BorderBrush="Black">
                    <TextBlock Text="{Binding qty}" VerticalAlignment="Center" FontSize="14" Margin="5 0" TextWrapping="Wrap"></TextBlock>
                </Border>
                <Border  Grid.Column="2"  BorderThickness="0.75" BorderBrush="Black">
                    <TextBlock Text="{Binding nama_produk}" VerticalAlignment="Center" FontSize="14" Margin="5 0" TextWrapping="Wrap"></TextBlock>
                </Border>
                <Border  Grid.Column="3"  BorderThickness="0.75" BorderBrush="Black">
                    <TextBlock Text="{Binding barcode}" VerticalAlignment="Center" FontSize="14" Margin="5 0" TextWrapping="Wrap"></TextBlock>
                </Border>
                <Border  Grid.Column="4"  BorderThickness="0.75" BorderBrush="Black">
                    <TextBlock Text="{Binding harga}" VerticalAlignment="Center" FontSize="14" Margin="5 0" TextWrapping="Wrap"></TextBlock>
                </Border>
                <Border Grid.Column="5" BorderThickness="0.75" BorderBrush="Black">
                    <TextBlock Text="{Binding total}" VerticalAlignment="Center" FontSize="14" Margin="5 0" TextWrapping="Wrap"></TextBlock>
                </Border>
            </Grid>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

I try printing using this code:

public static void print(dynamic param , bool use_dialog = false)
{
    PrintDialog printDlg = new PrintDialog();
    if (use_dialog == true)
    {
        if (printDlg.ShowDialog() == true)
        {
            printDlg.PrintVisual(param, "Printing data.");
        }
    }
    else
    {
        printDlg.PrintVisual(param, "Printing data.");
    }
}

This is my itemsource for my ListView:

public List<Detail_transaksi_model> ListProduk = new List<Detail_transaksi_model>();
public PrintPreviewDocument()
{
    InitializeComponent();
    int no = 0;
    for (int i = 0; i < 100; i++)
    {
        ListProduk.Add(new Detail_transaksi_model
            {
                no = no,
                barcode = "",
                harga = "",
                total = "",
                nama_produk = "",
                qty = 1,
            });
        no++;
    }
    LstProduk.ItemsSource = ListProduk;
}

and I got this result enter image description here

In my picture my PrintVisual didn't create next page for my list data and cut off. How to printVisual Long Listview ?

thank you for your answer, hope you all got have a nice day !



Read more here: https://stackoverflow.com/questions/64889256/print-long-listview-on-printvisual-c-sharp-wpf

Content Attribution

This content was originally published by Diky Ridhlo at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: