none
FlowDocument - Find does not find elements in Section

    Question

  • Hi,

      I have flowdocument with number of sections. When I load this document and Find the paragraph, it returns desired para. But when I load each section in a different flowdocument, and use find on this new flowdocument, it fails to find the paragraph.

    Do let me know what could be the reason.

    --------------------------Code ---------------------

    // load only a section into rtb as new FlowDocument

    string fn = "c:\\FlowDocument1.xaml";

    XmlReader xr = XmlReader.Create(fn);

    FlowDocument flowDoc = XamlReader.Load(xr) as FlowDocument;

    FlowDocument fdSection = new FlowDocument(flowDoc.FindName("Section1") as Section);

    rtb.Document = fdSection ;

    // Find para in rtb.Document and this fails

    Paragraph newnode = rtb.FindName("pFirst") as Paragraph;

    ---------------------------FlowDocument-----

    <FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    ColumnWidth="400" FontSize="14" FontFamily="Georgia"

    >

    <Section Name="Section1"

    <Paragraph Name="pInactive" FontWeight="Bold" FontSize="12">

    <Run>This para is inactive and user cant change it</Run>

    </Paragraph>

    <Paragraph Name="pChangeMe" FontWeight="Bold" FontSize="19">

    <Run>Please change me</Run>

    </Paragraph>

    <Paragraph>

    <Run FontSize="11" FontStyle="Oblique">This para too is inactive and user cant change it.</Run>

    </Paragraph>

    </Section >

    <Section Name="Section2"

    <Paragraph Name="pFirst" FontSize="12">

    <Run>This is result o first Action for the task</Run>

    </Paragraph>

    <Paragraph Name="pSecond">

    <Run FontSize="11" FontStyle="Oblique">This is second action for the task</Run>

    </Paragraph>

    </Section >

    </FlowDocument>

    Monday, November 06, 2006 11:31 PM

Answers

  • it seems to work fine...

    the only thing i corrected was to close the section tag

    <Section Name="Section1"    -->

    <Section Name="Section1">

    Monday, November 06, 2006 11:45 PM
  • This is definitely a bug. Thanks for identifying it
    Wednesday, November 08, 2006 3:34 AM

All replies

  • it seems to work fine...

    the only thing i corrected was to close the section tag

    <Section Name="Section1"    -->

    <Section Name="Section1">

    Monday, November 06, 2006 11:45 PM
  • Thanks for looking into.

    Yeah, that was typo.

    Its still not working at my side. I can's find the para in the section when section is loaded as flowdocument in rtb.

    //below statement returns Null value.this statement returns Null value and is handled on button click

    Paragraph peviewNode = this.rtbTask.Document.FindName("pChangeMe") as Paragraph;

     

    //flowdocument is attached to rtb at window loaded or some other event.

    string fn = "c:\\FlowDocument1.xaml";

    XmlReader xr = XmlReader.Create(fn);

    m_FlowDocTask = XamlReader.Load(xr) as FlowDocument;

    FlowDocument fdTask = new FlowDocument(m_FlowDocTask.FindName("fdsTaskDocu") as Section);

    this.rtbTask.Document = fdTask;

    //.............................Flowdoc c:\\FlowDocument1.xaml is as below..........................................

    <FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    ColumnWidth="400" FontSize="14" FontFamily="Georgia"

    >

    <Section Name="fdsTaskDocu">

    <Paragraph Name="pInactive" FontWeight="Bold" FontSize="12">

    <Run>This para is inactive and user cant change it</Run>

    </Paragraph>

    <Paragraph Name="pChangeMe" FontWeight="Bold" FontSize="19">

    <Run>Please change me</Run>

    </Paragraph>

    <Paragraph>

    <Run FontSize="11" FontStyle="Oblique">This para too is inactive and user cant change it.</Run>

    </Paragraph>

    </Section >

    <Section Name="fdsTaskResult" >

    <Paragraph Name="pFirst" FontSize="12">

    <Run>This is result o first Action for the task</Run>

    </Paragraph>

    <Paragraph Name="pSecond">

    <Run FontSize="11" FontStyle="Oblique">This is second action for the task</Run>

    </Paragraph>

    </Section >

    </FlowDocument>

    Tuesday, November 07, 2006 4:46 PM
  • i tried the following and it looks fine

    void Window1_Loaded(object sender, RoutedEventArgs e)

    {

    string fn = "c:\\new Folder\\Window1.xaml";

    XmlReader xr = XmlReader.Create(fn);

    FlowDocument m_FlowDocTask = XamlReader.Load(xr) as FlowDocument;

    FlowDocument fdTask = new FlowDocument(m_FlowDocTask.FindName("fdsTaskDocu") as Section);

    rtb1.Document = m_FlowDocTask;

    }

    void b_Click(object sender, RoutedEventArgs e)

    {

    Paragraph peviewNode = rtb1.Document.FindName("pChangeMe") as Paragraph;

    }

    Tuesday, November 07, 2006 5:33 PM
  • Sorry to say, but you missed one catch here.You are using original FlowDoc, i.e.  "m_FlowDocTask". Instead use new FlowDoc "fdTask"

    Just change your code as

    FlowDocument fdTask = new FlowDocument(m_FlowDocTask.FindName("fdsTaskDocu") as Section);

    //rtb1.Document = m_FlowDocTask;

    rtb1.Document =  fdTask ; // note flowdoc that I am attaching.

    Tuesday, November 07, 2006 6:18 PM
  • This is definitely a bug. Thanks for identifying it
    Wednesday, November 08, 2006 3:34 AM
  • I appreciate your efforts.

    When can we expect this to be fixed, interms of timeline.

    Thanks,

    Mahesh

    Wednesday, November 08, 2006 2:53 PM