Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide a Paragraph in a FlowDocument?

Is there any way to use databinding to show or hide a Paragraph within a FlowDocument? (I want to use MVVM, but with a FlowDocument as my view.)

Paragraph doesn't have a Visibility property. I'm not sure what else to look for.

like image 205
Joe White Avatar asked Aug 10 '09 12:08

Joe White


2 Answers

I tried Chris Bova's answer, but it had a couple problems:

  1. Text selection didn't work right
  2. The text inside didn't flow like a paragraph

My solution was to add and remove the paragraph from the flow document.

The steps are:

  1. Name the flow document (ie flowDocument)
  2. Name the item before the paragraph you want to hide (ie previousBlock)
  3. Name the paragraph you want to hide (ie hideParagraph)

Then:

        if (<hide paragraph>)
        {
            if (previousBlock.NextBlock == hideParagraph)
            {
                flowDocument.Blocks.Remove(hideParagraph);
            }
        }
        else
        {
            if (previousBlock.NextBlock != hideParagraph)
            {
                flowDocument.Blocks.InsertAfter(previousBlock, hideParagraph);
            }
        }
like image 172
tster Avatar answered Sep 19 '22 04:09

tster


I had the exact same problem and handled it successfully by wrapping the content of the ListItem in a InlineUIContainer, like so:

  <ListItem>
    <Paragraph>
      <InlineUIContainer>
        <TextBlock x:Name="HideMe" Visibility="Collapsed">
          <Hyperlink NavigateUri="...">Components</Hyperlink>
        </TextBlock>
      </InlineUIContainer>
    </Paragraph>
  </ListItem>

From here you can set the visbility of "HideMe" in code or through a binding.

like image 41
Chris Bova Avatar answered Sep 21 '22 04:09

Chris Bova