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.
I tried Chris Bova's answer, but it had a couple problems:
My solution was to add and remove the paragraph from the flow document.
The steps are:
Then:
if (<hide paragraph>)
{
if (previousBlock.NextBlock == hideParagraph)
{
flowDocument.Blocks.Remove(hideParagraph);
}
}
else
{
if (previousBlock.NextBlock != hideParagraph)
{
flowDocument.Blocks.InsertAfter(previousBlock, hideParagraph);
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With