Das ist die Funktion, vor der ich stehe ein Problem.
Code: Select all
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();
}
In diesem Fenster habe ich Ich habe ein Vorlagenraster erstellt, das ich jedes Mal fülle, wenn die WPF-Elemente übergeben werden, und anschließend das Raster zurückgebe.
Wenn ich nur
Die SCECOND -Zeit wird das erste Element in meiner Füllungs -Templates -Liste überschrieben. Ich gehe davon aus, dass dies daran liegt, dass ich das gleiche Netz verwende und es jedes Mal überschreibe.public Grid FillPrintGridTemplate(ListBox listBox)
{
Grid virtualGrid = new Grid();
Label[] wnrLabels = { lbl_WNR1, lbl_WNR2, lbl_WNR3, lbl_WNR4, lbl_WNR5, lbl_WNR6 };
Label[] UniqueNumberLabels = { lbl_UniqueNumber1, lbl_UniqueNumber2, lbl_UniqueNumber3, lbl_UniqueNumber4, lbl_UniqueNumber5, lbl_UniqueNumber6 };
Label[] MATNRLabels = { lbl_MATNR1, lbl_MATNR2, lbl_MATNR3, lbl_MATNR4, lbl_MATNR5, lbl_MATNR6 };
Image[] QRCodeImage = { qrCodeImage1, qrCodeImage2, qrCodeImage3, qrCodeImage4, qrCodeImage5, qrCodeImage6 };
ResetElements(wnrLabels, UniqueNumberLabels, MATNRLabels, QRCodeImage);
// Iterate over each item in the ListView
int i = 0;
foreach (var obj in listBox.Items)
{
// Cast the item to UniqueNumberItem
UniqueNumberItem item = obj as UniqueNumberItem;
if (item != null)
{
// Now that we've ensured 'item' is a UniqueNumberItem, we can access its properties
wnrLabels.Content = item.WNR;
UniqueNumberLabels.Content = item.UniqueNumber;
MATNRLabels.Content = item.Matnr;
// Generate QR code for the Unique Number
BitmapImage qrCodeImage = GenerateQRCode(item.UniqueNumber);
// Set the Image control's Source to the QR code
QRCodeImage.Source = qrCodeImage;
i++; // Move to the next index for the next item
}
}
return MainGrid;
}
[/code]
Ich habe darüber nachgedacht, ob es möglich ist, so etwas wie einen Klon des Rasters oder einiger temporärer Rasterelemente zu erstellen, natürlich mit ihren untergeordneten Elementen. So überschreibe ich nicht jedes Mal dasselbe Raster und löse mein Problem. Oder gibt es einen besseren Weg, dies zu erreichen?
Nur um Ihnen eine Vorstellung zu geben, so sieht es aus. Außerdem bekomme ich jedes Mal zufällig ein leeres Blatt Papier, aber das ist wohl ein weiteres Problem
[img]https://i.sstatic.net /TMYDurXJ.png[/img]
Code: Select all
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();
}
}