如何防止缠绕在WPF的FlowDocument在C#代码? [英] How can I prevent wrapping in a WPF FlowDocument in C# code?
问题描述
研究证明这是为了防止包装的方式,比方说,一个段落:
Studies have shown this is the way to prevent wrapping in, say, a Paragraph:
<Paragraph>
<TextBlock TextWrapping="NoWrap">unwrapping text</TextBlock>
</Paragraph>
我怎样才能获得在C#代码的行为?
How can I get the behavior in C# code?
new Paragraph(new TextBlock()
{
Text = "unwrapping text",
TextWrapping = TextWrapping.NoWrap
});
收益率无法从System.Windows.Controls.TextBlock'到'转变System.Windows.Documents.Inline
,因为段落的构造函数期待一个内联。
Yields cannot convert from 'System.Windows.Controls.TextBlock' to 'System.Windows.Documents.Inline'
because Paragraph's constructor is expecting an Inline.
我似乎无法找到一个方法来转换TextBlock的为嵌入,使段落高兴。如果它工作在XAML中,应该有一个转换器的地方,对不对?我要如何找到它
I can't seem to find a way to convert a TextBlock to an Inline to make Paragraph happy. If it works in XAML, there should be a converter somewhere, right? How do I find it?
编辑:我实现的FlowDocument的一点是东西来包装和流量,并重新可观,等我在写一些简单的介绍,只是一些 System.Windows.Documents.Table
s的数据的,不幸的是,它包装的第一列是其中一个包含日期,所以
I realize the point of a FlowDocument is for things to wrap and flow and be re-sizable, etc. I'm writing some simple reports, just some System.Windows.Documents.Table
s of data, and unfortunately the first column that wraps is one which contains dates, so
2013-04-24
变为
2013-04-
24
我一直在使用运行
这么远,虽然他们有一些的TextBlock
的属性,它们并没有 TextWrapping
或 TextTrimming
启示。
I've been using Run
s so far, and while they have some TextBlock
properties, they offer no TextWrapping
or TextTrimming
affordances.
推荐答案
您要添加的的TextBlock
来的内联,构造赢得'T为您代劳。我认为这将是最简单的只写:
You want to add the TextBlock
to the inlines, the constructor won't do it for you. I think it would be easiest to just write:
var p = new Paragraph();
p.Inlines.Add(new TextBlock()
{
Text = "unwrapping text",
TextWrapping = TextWrapping.NoWrap
});
这篇关于如何防止缠绕在WPF的FlowDocument在C#代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!