如何在FlowDocument中隐藏段落? [英] How can I hide a Paragraph in a FlowDocument?

查看:114
本文介绍了如何在FlowDocument中隐藏段落?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用数据绑定来显示或隐藏FlowDocument中的段落? (我想使用MVVM,但使用FlowDocument作为我的观点。)



段落没有Visibility属性。我不知道还有什么要找的。

解决方案

我试过Chris Bova的答案,但有几个问题: / p>


  1. 文本选择不正确

  2. 内部的文本不像段

我的解决方案是从流程文档添加和删除段落。



步骤是:


  1. 命名流文档(即flowDocument) / li>
  2. 在您要隐藏的段落之前命名项目(即previousBlock)

  3. 命名要隐藏的段落(即hideParagraph)

然后:

  if(< hide段落>)
{
if(previousBlock.NextBlock == hideParagraph)
{
flowDocument.Blocks.Remove(hideParagraph);
}
}
else
{
if(previousBlock.NextBlock!= hideParagraph)
{
flowDocument.Blocks.InsertAfter(previousBlock, hideParagraph);
}
}


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:

  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);
            }
        }

这篇关于如何在FlowDocument中隐藏段落?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆