开发者

Add Checkbox to Paragraph

Hy!

I want to add a checkbox to a paragraph.

My code:

        PrintDialog pd = new PrintDialog();
        pd.ShowDialog();
        FlowDocument doc = new FlowDocument();
        Paragraph ph = new Paragraph();
        ph.Inlines.Add(new Bold(new Run("TODO\n")));
        foreach (CheckBox cb in box.Items)
        {
            int value = Convert.ToInt32("0x6F", 1开发者_Go百科6);
            string stringValue = Char.ConvertFromUtf32(value);
            CheckBox bt = new CheckBox();
            bt.IsChecked = false;
            ph.Inlines.Add(new Run(bt + " "+cb.Content.ToString()));
        }
        doc.Name = "FlowDoc";
        doc.Blocks.Add(ph);
        IDocumentPaginatorSource idpSource = doc;
        pd.PrintDocument(idpSource.DocumentPaginator, "Hello WPF Printing."); 

the output is wrong:

TODO System.Windows.Controls.CheckBox Content: IsChecked:False hahaSystem.Windows.Controls.CheckBox Content: IsChecked:False haha1System.Windows.Controls.CheckBox Content: IsChecked:False hallo

Please help!


You could use BlockUIContainer http://msdn.microsoft.com/en-us/library/system.windows.documents.blockuicontainer.aspx

PrintDialog pd = new PrintDialog();
pd.ShowDialog();
FlowDocument doc = new FlowDocument();
Paragraph ph = new Paragraph();
StackPanel sp = new StackPanel();
BlockUIContainer buc = new BlockUIContainer(sp);
ph.Inlines.Add(new Bold(new Run("TODO\n")));

foreach (CheckBox cb in box.Items)
{
    int value = Convert.ToInt32("0x6F", 16);
    string stringValue = Char.ConvertFromUtf32(value);
    CheckBox bt = new CheckBox();
    bt.IsChecked = false;
    bt.Content = cb.Content;
    //ph.Inlines.Add(new Run(bt + " " + cb.Content.ToString()));
    sp.Children.Add(bt);
 }

        doc.Name = "FlowDoc";
        doc.Blocks.Add(ph);
        doc.Blocks.Add(buc);
 IDocumentPaginatorSource idpSource = doc;
 pd.PrintDocument(idpSource.DocumentPaginator, "Hello WPF Printing."); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜