使用 xaml 将图像加载到 silverlight richtextarea 中
我从 MSDN 文档中知道,您无法使用 XAML 属性导出属于 RichTextBox 一部分的图像。这很好,我可以通过手动反思和查看块来解决这个问题。
我的问题是,如果我手动重新构建 XAML 以包含图像,RichTextBox 是否能够从 xaml 加载它。
我已经实现了反射和手动 XAML 导出,并且无需图像即可完美运行。
对于图像,它会生成以下内容:
<Section xml:space="preserve" HasTrailingParagraphBreakOnPaste="False" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Paragraph TextAlignment="Left" FontSize="20" FontFamily="Portable User Interface" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" Foreground="#FF000000" >
<Run Text="Test" FontSize="20" FontFamily="Portable User Interface" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" Foreground="#FF000000" />
</Paragraph>
<Paragraph TextAlignment="Left" FontSize="20" FontFamily="Portable User Interface" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" Foreground="#FF000000" >
<InlineUIContainer>
<Image Source="./desert.jpg" Height="150" Width="200" />
</InlineUIContainer>
<Run Text="" FontSize="20" FontFamily="Portable User Interface" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" Foreground="#FF000000" />
</Paragraph>
</Section>
我通过 XAML 属性将其反馈到 RTB 并中断! (异常是无用的,只是一个 IllegalArgmentException 说“值”。
如果你只取出 InlineUIContainer 部分,那就没问题了!
我无法确定是否可能是图像位置错误或 RichTextBox 只是不接受图像的问题 (
我认为可能从 xaml 指定图像的唯一原因是因为 MSDN 文档显示了它: http://msdn.microsoft.com/en-us/library/ee681613(VS.95).aspx。
有什么想法吗?
Ta,
Andy。
I know from MSDN documentation that you cannot export an Image which is part of a RichTextBox using the XAML property. This is fine, I can work around that by relection and looking through the blocks manually.
My question is, if I re-build the XAML manually to include an Image, would the RichTextBox be able to load it from xaml.
I've implemented the reflection and manual XAML export already and it works perfectly without images.
With images it produces this:
<Section xml:space="preserve" HasTrailingParagraphBreakOnPaste="False" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Paragraph TextAlignment="Left" FontSize="20" FontFamily="Portable User Interface" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" Foreground="#FF000000" >
<Run Text="Test" FontSize="20" FontFamily="Portable User Interface" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" Foreground="#FF000000" />
</Paragraph>
<Paragraph TextAlignment="Left" FontSize="20" FontFamily="Portable User Interface" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" Foreground="#FF000000" >
<InlineUIContainer>
<Image Source="./desert.jpg" Height="150" Width="200" />
</InlineUIContainer>
<Run Text="" FontSize="20" FontFamily="Portable User Interface" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" Foreground="#FF000000" />
</Paragraph>
</Section>
Which I feed back into the RTB via the XAML property and breaks! (The exception is useless, just an IllegalArgmentException saying 'Value'.
If you take out just the InlineUIContainer section its fine!
I can't work out if its possibly a problem with the image location being wrong or the RichTextBox just not accepting images apart from in-code.
The only reason why I think it's possibly to specify an image from xaml is because the MSDN documents shows it: http://msdn.microsoft.com/en-us/library/ee681613(VS.95).aspx.
Any ideas?
Ta,
Andy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
RichTextBox
上的Xaml
属性不支持 in 或 out 的InlineUIContainer
。我首先尝试的一种解决方法是在 xaml 上使用 XamlReader,然后将结果添加到
RichTextBox.Blocks
集合中:-The
Xaml
property on theRichTextBox
does not supportInlineUIContainer
either in or out.One work around I would try first is to use the XamlReader on your xaml instead then add the result to the
RichTextBox.Blocks
collection:-好吧,我找到了一种方法来做到这一点,无论如何,不要使用 XAML 属性将 XAML 直接加载到 RTB 中。
要将带有图像的 XAML 加载到 RTB 中,我必须恢复为首先使用 XamlReader 对象将 XAML 加载到对象中,然后按照以下代码逐一添加块:
不像我所帮助的那么简洁,但我猜测 XAML 属性只是不解析 InlineUIElements。
安迪.
Well, I've found a way to do it, all-be-it not loading the XAML straight into the RTB using the XAML property.
To load XAML with images into the RTB I've had to revert to loading the XAML into objects first using the XamlReader object, then adding the blocks one by one, as per this code:
Not as neat as I would have helped, but I guess the XAML property just doesn't parse InlineUIElements.
Andy.
在 XAML ./desert.jpg 源中将不起作用。相反,使用这个
这里有两个重要的关键字,第一个是您的命名空间ProjectBus,
第二个是固定的“组件”,
然后是您需要编写的图像路径。
否则,即使它在设计时可以显示,有时它在运行时也不起作用。
比如
希望有帮助
In XAML ./desert.jpg source will not work. Instead use this one
Here are two important keywords first one is your namespace ProjectBus
The secondone is fixed "component"
then your imagepath you need to write.
Otherwise even if its displayable on designtime sometimes it doesnt work on runtime.
such as
Hope helps