Создать виртуальную копию элемента сетки и добавить в документ XPSC#

Место общения программистов C#
Ответить
Anonymous
 Создать виртуальную копию элемента сетки и добавить в документ XPS

Сообщение Anonymous »

Мое приложение создает на основе пользовательского ввода некоторые уникальные числа и отображает их в виде QR-кодов, чтобы их можно было распечатать.
Это функция, с которой я столкнулся проблема.
private void Button_Click(object sender, RoutedEventArgs e)
{
listBox10.Visibility = Visibility.Collapsed;
PrintGrid.Visibility = Visibility.Visible;

GenerateUniqueNumber_v2.PrintTemplate printTemplate = new GenerateUniqueNumber_v2.PrintTemplate();

// Create a temporary ListBox to hold items for printing
ListBox tempListBox = new ListBox();

// Create a list to hold the filled templates
List filledTemplates = new List();

// Iterate over the items in the ListBox
for (int i = 0; i < listBox10.Items.Count; i++)
{
// Add the current item to the temporary ListBox
tempListBox.Items.Add(listBox10.Items);

// Check if we have collected 6 items or if we are at the last item
if ((i + 1) % 6 == 0 || i == listBox10.Items.Count - 1)
{
// Call the print method with the current batch of items
var filledTemplate = printTemplate.FillPrintGridTemplate(tempListBox);
filledTemplates.Add(filledTemplate); // Add the filled template to the list
filledTemplate = null;
//filledTemplates.Add(printTemplate.FillPrintGridTemplate(tempListBox));
//Print_WPF_Preview(printTemplate.FillPrintGridTemplate(tempListBox));
// Clear the temporary ListBox for the next batch
tempListBox.Items.Clear();
tempListBox = new ListBox();
//printTemplate.Close();
}
}

Print_WPF_Preview(filledTemplates);

//printTemplate.Show();
// Close the print template if needed
//printTemplate.Close();
}

У меня есть список с включенными элементами. Поскольку на одной странице печати может отображаться только 6 элементов, я проверяю, есть ли у меня 6 элементов или последний элемент, и передаю их методу FillPrintGridTemplate.
В этом окне я создал сетку шаблона, которую я заполняю каждый раз, когда она передает элементы WPF, и после этого возвращаю сетку.
Когда у меня есть только
Я думал о том, можно ли создать что -то вроде клона сетки или некоторых временных элементов сетки, конечно, со своими детскими элементами. Поэтому я не буду перезаписывать одну и ту же сетку каждый раз и решать свою проблему. Или есть лучший способ сделать это? Я также получаю случайную пустую бумагу между каждый раз, но я думаю, что это еще одна проблема
< /p>
public static void Print_WPF_Preview(List wpf_Elements)
{
string sPrintFileName = "print_preview.xps";

if (File.Exists(sPrintFileName))
{
File.Delete(sPrintFileName);
}

// Create XPS document
using (XpsDocument doc = new XpsDocument(sPrintFileName, FileAccess.ReadWrite))
{
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
SerializerWriterCollator output_Document = writer.CreateVisualsCollator();
output_Document.BeginBatchWrite();

// Iterate over each FrameworkElement and write it to the document
foreach (var element in wpf_Elements)
{
output_Document.Write(element);
// Add a new page for each element
output_Document.Write(new PageContent());
}

output_Document.EndBatchWrite();

// Open the document for preview
FixedDocumentSequence preview = doc.GetFixedDocumentSequence();
GenerateUniqueNumber_v2.PrintWindow printWindow = new GenerateUniqueNumber_v2.PrintWindow(preview);
printWindow.Show();
}
}


Подробнее здесь: https://stackoverflow.com/questions/793 ... s-document
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»