需要在 中RichTextBox
分别插入文字中文字的位置图片,使左右换行。
我目前正在使用这样的东西。
string[] messageSplit = message.Split(' ');
FlowDocument doc = new FlowDocument();
Paragraph paragraph = new Paragraph();
for (int i = 0; i < messageSplit.Length; ++i) {
string str = messageSplit[i];
if (str.Contains("${emoteId=")) {
string id = ...
Image image = new Image();
image.Source = (ImageSource)((new ImageSourceConverter()).ConvertFromString($@"emotes/{id}.png"));
BlockUIContainer cont = new BlockUIContainer(image);
Figure figure = new Figure(cont);
figure.Width = (new FigureLength(24));
figure.WrapDirection = WrapDirection.Both;
figure.VerticalAnchor = FigureVerticalAnchor.PageTop;
figure.HorizontalAnchor = FigureHorizontalAnchor.PageLeft;
paragraph.Inlines.Add(figure);
} else {
paragraph.Inlines.Add(new Run(str));
}
doc.Blocks.Add(paragraph);
MessageText.Document = doc;
但是有了这样的插入,所有被转移到顶部的文本,所有的图片都出现在了底部。
如何正确插入文本?
文本本身看起来像这样qqq ${emoteId=4} www ${emoteId=5} ${emoteId=20} eee
1 个回答