2010-03-01 10 views
14

क्यों प्रिंट करती है मेरे पास मेरे WPF ऐप में एक सूची दृश्य है जो कार्य करने के लिए कार्यों के संग्रह से जुड़ा हुआ है (एक टू-डू सूची)। मैं चाहता हूं कि उपयोगकर्ता अपनी सूची प्रिंट कर सके और एमएसडीएन दिशानिर्देशों के आधार पर निम्नलिखित कोड बनाया हो। (यह मेरा मुद्रण में प्रथम प्रयास का)यह फ़्लॉवॉक तालिका हमेशा 2 कॉलम

public FlowDocument GetPrintDocument() 
{ 
    FlowDocument flowDoc = new FlowDocument(); 
    Table table = new Table(); 

    int numColumns = 3; 

    flowDoc.Blocks.Add(table); 

    for(int x=0;x<numColumns;x++) 
    { 
     table.Columns.Add(new TableColumn()); 
    } 
    GridLengthConverter glc = new GridLengthConverter(); 
    table.Columns[0].Width = (GridLength)glc.ConvertFromString("300"); 
    table.Columns[1].Width = (GridLength)glc.ConvertFromString("50"); 
    table.Columns[2].Width = (GridLength)glc.ConvertFromString("50"); 

    table.RowGroups.Add(new TableRowGroup()); 

    table.RowGroups[0].Rows.Add(new TableRow()); 
    // store current working row for reference 
    TableRow currentRow = table.RowGroups[0].Rows[0]; 

    currentRow.FontSize = 16; 
    currentRow.FontWeight = FontWeights.Bold; 

    currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Subject")))); 
    currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Due Date")))); 
    currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Urgency")))); 

    for (int i = 1; i < issues.Count+1; i++) 
    { 
     table.RowGroups[0].Rows.Add(new TableRow()); 
     currentRow = table.RowGroups[0].Rows[i]; 
     currentRow.FontSize = 12; 
     currentRow.FontWeight = FontWeights.Normal; 

     currentRow.Cells.Add(new TableCell 
          (new Paragraph 
          (new Run 
          (issues[i - 1].IssSubject)))); 
     currentRow.Cells.Add(new TableCell 
          (new Paragraph 
          (new Run 
          (issues[i - 1].IssDueDate.Date.ToString())))); 
     currentRow.Cells.Add(new TableCell 
          (new Paragraph 
          (new Run 
          (issues[i - 1].IssUrgency.ToString())))); 
    } 
    return flowDoc; 
} 

जब मैं निम्नलिखित कोड मैं हमेशा है मेरा पेज 2 कॉलम (प्रत्येक तालिका के 3 कॉलम युक्त) के साथ नीचे विभाजित बीच के साथ मुद्रित करने के लिए प्रयास करें। मैंने विभिन्न ग्रिडलेथेंथ मानों का प्रयास किया है लेकिन कोई सफलता नहीं मिली है।

printDialog.PrintDocument(((IDocumentPaginatorSource)StatusBoardViewModel 
       .GetPrintDocument()) 
       .DocumentPaginator 
      ,"Flow Document Print Job"); 

उत्तर

19

मुझे लगता है कि उत्तर पाने का सबसे अच्छा तरीका छोड़ना और पूछना है, तो आप इसे स्वयं पाते हैं।

यह समस्या पृष्ठों को मुद्रित करने के लिए लाइन में थी, न कि फ्लोडोक स्वयं। डिफ़ॉल्ट रूप से वे 2 कॉलम के साथ प्रिंट करते हैं। को सही कोड है (यह भी मार्जिन और प्रिंट करने योग्य क्षेत्र के साथ संबंधित):

PrintDialog printDialog = new PrintDialog(); 

if (printDialog.ShowDialog() == true) 
{ 

    FlowDocument flowDoc = statusBoardViewModel.GetPrintDocument(); 

    flowDoc.PageHeight = printDialog.PrintableAreaHeight; 
    flowDoc.PageWidth = printDialog.PrintableAreaWidth; 
    flowDoc.PagePadding = new Thickness(25); 

    flowDoc.ColumnGap = 0; 

    flowDoc.ColumnWidth = (flowDoc.PageWidth - 
          flowDoc.ColumnGap - 
          flowDoc.PagePadding.Left - 
          flowDoc.PagePadding.Right); 

    printDialog.PrintDocument(((IDocumentPaginatorSource)flowDoc) 
          .DocumentPaginator, 
          "Task Manager Print Job"); 

} 

तरह से मैं जो मैं अत्यधिक की सलाह देते हैं "सी # 2008 में प्रो WPF" में मैथ्यू मैकडोनाल्ड के इस पाया गया।

3

जानकारी के लिए धन्यवाद। मैं बस की तरह columnwidth की स्थापना करके यह तय: flowDoc.ColumnWidth = pageSize.Width

FYI कभी netframeworkdev या नेट फ्रेमवर्क से मदद का विकास करना b/c वे अच्छे जवाब कभी नहीं प्राप्त करने की कोशिश नहीं करते। मेरी इच्छा है कि मेरे खोज इंजन ने मुझे उस बेकार साइट के बजाय स्टैक ओवरव्लो पर इंगित किया होगा। StackOverflow हमेशा जवाब है। :) एक बार फिर धन्यवाद।

(काश तुम सिर्फ कभी अपने खोज परिणामों में प्रदर्शित होने से साइटों को ब्लॉक कर सकता है, आप कैसे करना है कि कृपया मुझे बताओ पता है।)

+0

मैं आपको बता नहीं सकता कि कितनी बार मैं कामना मैं से एक साइट छुपा सकते मेरी खोज परिणाम। –

संबंधित मुद्दे