我有一个绑定到属性的TextBlock.但是,我想在文中强调某些词语.最简单的方法是什么?仅供参考,我是WPF的新手.
我的问题出现在.NET 3.5 SP1中的WPF,可以描述如下:
我有一个默认Style
命中TextBlock
我的UI中的所有元素.这就是它的样子:
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextTrimming" Value="CharacterEllipsis"/>
<Setter Property="Foreground" Value="Red"/>
</Style>
Run Code Online (Sandbox Code Playgroud)
这适用于所有人TextBlock
.除此之外,我有一个Button
样式,包括ControlTemplate
看起来像这样(缩短):
<Style x:Key="MyButtonStyle" TargetType="{x:Type Button}" BasedOn="{x:Null}">
<Setter Property="Foreground" Value="Green"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="Border"
Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
Height="24"
BorderBrush="{TemplateBinding BorderBrush}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
TextBlock.Foreground="{TemplateBinding Foreground}"/>
</Border>
<ControlTemplate.Triggers>...</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
请注意行TextBlock.Foreground="{TemplateBinding Foreground}"
中ContentPresenter
.这应该将按钮文本设置为绿色,实际上它在Visual Studio的设计器视图中.但是当我编译并运行程序时,按钮文本为红色,文本颜色由默认TextBlock
样式设置.我用Snoop验证了这一点.
如何防止默认TextBlock
样式覆盖该TextBlock.Foreground
值?在这种情况下,OverridesDefaultStyle
财产ContentPresenter …
我想在不更改文本块的字体大小的情况下拉伸WPF Textblock中的文本?
我正在尝试复制Inline inline;
一个新的Inline tempInline
以便构建TextBlock textbox = new TextBlock(tempInline);
这样的tempInline = inline;
但是问题是,当我这样做时,我的原始inline
更改/被修改.
我怎么能这样做,内联没有复制或克隆方法.
我更换ContentPresenter
的DataGridCell
的Template
用TextBlock
的,现在我搜索正确Binding
的内容.
正常的方法是Text="{TemplateBinding Content}
在TextBlock
-这是行不通的.也Text="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Content, Mode=TwoWay}"
行不通.
还有其他想法吗?
tesseract OCR具有命令行界面,该界面使我们能够从带有某些参数的图像中识别文本。
输入argumetns是imagename(路径图)outputbase和(识别文本的名称)-psm pagesegmode参数。
pagesegmode的值为: 0 =仅方向和脚本检测(OSD)。 1 =使用OSD进行自动页面分割。 2 =自动页面分割,但没有OSD或OCR 3 =全自动页面分割,但没有OSD。(默认) 4 =假设一列可变大小的文本。 5 =假定单个统一的垂直对齐文本块。 6 =假设一个统一的文本块。 7 =将图像视为单个文本行。 8 =将图像视为一个单词。 9 =将图像当作一个单词圈起来。 10 =将图像视为单个字符。 -l lang和/或-psm pagesegmode必须出现在anyconfigfile之前。
但是它可以将识别的文本块的位置和大小写到特定文件中还是它是内部信息?
TextBlock具有KeyDown和KeyUp事件,但从未触发过。有办法实现吗?我只需要检测是否按下了任何键。
我有一个TextBlock我想传递' LineSpacing ' 的属性.用"的东西线高 "与LineStackingStrategy ="BlockLineHeight"的是,它也适用该线高到第一行之前的部分:
TextblockEx http://i61.tinypic.com/2a5y9mw.jpg
如何管理维护说:" LineSpacing ",而无需修改线高的第一行之前?
我可能会做的一件事是将FlowDocument的Paragraph中的每一行分开,因为Paragraph有一个属性Spacing Before Line和Spacing After Line.
任何帮助都会得到真正的赞赏.提前致谢.
回答
看来你可以使用LineStackingStrategy ="MaxHeight"来避免在第一行上领先.(查看下面的答案以获取详细信息).
PS感谢Mitch的启示:D
我TextBlock
在其中放了2个Inline
s Run
,HorizontalAlignment
TextBlock的设置为Center,这没关系,我只想将第一个Run比较到第二个,这是我的代码:
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="/Throne;component/Fonts/#Segoe UI Light" FontSize="35" FontWeight="Bold" Visibility="{Binding UserNameTextBlockVisibility}">
<Run FontSize="25">En tant que :</Run>
<LineBreak />
<Run Text="{Binding UserName}" Foreground="ForestGreen"/>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)
这是我得到的结果:
我想要实现的目标:
我试图搜索文档和互联网上的线程,但我没有找到实现这一目标的方法,我怎么能意识到这一点?
我有一些XAML:
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="KeyLWP" TextWrapping="Wrap" MaxWidth="120">A Letter or Word or Phrase
</TextBlock>
<StackPanel>
<RadioButton x:Name="rdbtnCandidateVal1" Content="Two wrongs don't make a Wright Brothers Grimm was the Thingamabob Dylan Thomas Jefferson Airplane">
</RadioButton>
Run Code Online (Sandbox Code Playgroud)
...其中,使用分配给RadioButton内容的长字符串,它只是从地球边缘掉落.如果需要,我如何使用TextBlock的TextWrapping和MaxWidth属性来包装它?或者我必须将TextBlock与每个RadioButton配对,避开RadioButton的Content/Text属性吗?