T
T
Termir9882018-04-23 16:49:15
WPF
Termir988, 2018-04-23 16:49:15

WPF. How to print WrapPanel?

It is necessary to send to print (to the printer) WrapPanel with different elements. I created several UserControls and populate them with Children.Add(MyUserControl)
I print with:

var visualsPage = new List<Visual>();
var dialog = new PrintDialog();
            if (dialog.ShowDialog() == true)
            {
    //Подготовка к печати
             }

        dialog.PrintDocument(new Paginator(visualsPage.ToArray()), "Печать");

1) The actual question is how to convert the WrapPanel to a Visual (To put it in a visualsPage)
2) Is it possible (is it worth it) to modify the old way so that you can use several types of elements in the WrapPanel
Previously worked with one type of elements in the WrapPanel
for (int i = 0; i < IcBook.Items.Count; i++)
                {
                    page.Add((Visual)IcBook.ItemContainerGenerator.ContainerFromIndex(i));
                }

Where the icbook looked something like this:
<Grid Name="MainGrid">
        <ItemsControl Name="IcBook" ItemsSource="{Binding}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Grid/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <ItemsControl ItemsSource="{Binding LebelList}" Padding="20">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel/>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Border Width="376.5" BorderBrush="Black" BorderThickness="3">
                                    <Grid>
<!--Структура элемента WP-->

                                    </Grid>
                                </Border>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question