删除 C# Flowdocument 元素之间的空格?
我希望能够删除 FlowDocument 的各种内联元素之间的空白。下面是一个非常具体的例子,只是为了清楚地说明问题。所需的输出是“Hello World?”但发生的是“Hello World?”。在这种情况下 ”?”是一个可点击的按钮。
我搜索了一段时间没有成功。我尝试了所有形式的焊盘/边距调整,但它们只能增加间距。我开始相信该空间是 FlowDocument 元素边界所固有的。这似乎是一个系列限制。
<RichTextBox>
<FlowDocument>
<Paragraph Margin="0">
<Run>
Hello World
</Run>
<InlineUIContainer>
<Button Click="ButtonClick">?</Button>
</InlineUIContainer>
</Paragraph>
</FlowDocument>
</RichTextBox>
I would like to be able to remove the white spaces between various inline elements of a FlowDocument. Below is a very specific example just to make the problem clear. The desired output is "Hello World?" but what happens is "Hello World ?". In this case "?" is a clickable button.
I have searched for a while without success. I tried all forms of pad/margin adjustment, but they can only increase the spacing. I am beginning to believe the space is inherent to FlowDocument element boundaries. This seems like a series limitation.
<RichTextBox>
<FlowDocument>
<Paragraph Margin="0">
<Run>
Hello World
</Run>
<InlineUIContainer>
<Button Click="ButtonClick">?</Button>
</InlineUIContainer>
</Paragraph>
</FlowDocument>
</RichTextBox>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尽管格式看起来很丑陋,但在基于 XML 的 XAML 中,如果您想避免运行之间出现空格,则不能在元素的结束标记和开始标记之间留有任何空格。
试试这个:
As ugly as the formatting might seem, in XML based XAML, if you want to avoid whitespace between runs you cannot allow any space between the close and open tags of the elements.
Try this:
好的,这个问题是由于特殊的空格处理规则
解决方案的想法:
预处理 xaml,删除标签之间的新行/空白字符。
实现:
加载它,使用以下代码删除空格:
将资源字典添加到实体的资源中,应该使用段落:
就这样,不会创建任何内部有空格的额外 Runs。
我正在使用我们自己的自定义可本地化 ResorceDictionary 后代,它可以选择删除空格并自动处理所有这些内容。
Ok, this problem is beacuse of special whitespace handling rules.
Idea of the solution:
Preprocess xaml removing new line/whitespace characters between the tags.
Implementation:
Load it, remove whitespaces using the following code:
Add the resource dictionary to the resources of the entity, wich should use the Paragraph:
That`s all, no additional Runs with whitespaces inside will be created.
I`m using our own custom localizable ResorceDictionary descendant, wich has an option to remove whitespaces and is processing all this stuff automatically.
您可以向按钮添加负边距以使其更贴近:
You could add negative margins to the button to make it fit closer: