Мое приложение создает на основе пользовательского ввода некоторые уникальные числа и отображает их в виде 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
Создать виртуальную копию элемента сетки и добавить в документ XPS ⇐ C#
Место общения программистов C#
-
Anonymous
1737898464
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[i]);
// 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();
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79386496/create-a-virtual-copy-of-grid-element-and-add-to-xps-document[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия