【发布时间】:2015-05-22 12:50:00
【问题描述】:
我一直在尝试为文本块的一部分设置背景颜色。由于 TextBlock 本身没有此功能,我想我应该添加内联。
但是,内联对象(例如 Run、Span)有一个私有背景字段,该字段从父 TextBlock 获取其值。
我想我会尝试使用 InlineUIContainer。这是我使用的代码:
Grid grid = new Grid();
grid.Background = new SolidColorBrush(Colors.Red);
TextBlock block = new TextBlock();
block.Text = temp2;
grid.Children.Add(block);
InlineUIContainer iuic= new InlineUIContainer();
iuic.Child = grid;
Parent_TextBlock.Inlines.Add(iuic);
最后一行给出了一个 ArgumentException。有没有办法改变 TextBlocks 背景颜色的一部分?如果是这样,我是否走在正确的轨道上?
【问题讨论】:
-
你不能使用
TextBlock.Background属性吗? -
在 WindowsPhone TextBlock 中不包含 Background 属性,仅在 WPF 中
-
我想改变文本块背景的一部分,而不是整个背景。基本上我的字符串很长,需要“突出显示”一个单词。所以使用文本块的背景属性不会做我想做的事,在这种情况下
-
@f14shm4n 我不知道,抱歉。
标签: c# xaml windows-phone-8.1 windows-8.1 win-universal-app