将复选框添加到段落

时间:2010-11-08 07:33:58

标签: c# wpf wpf-controls

HY!

我想在段落中添加一个复选框。

我的代码:

        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", 16);
            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."); 

输出错误:

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

请帮忙!

1 个答案:

答案 0 :(得分:0)

您可以使用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.");