2010-12-16 71 views
1

我从MSDN文档中了解到,无法使用XAML属性导出属于RichTextBox一部分的图像。这很好,我可以通过选择并手动查看块来解决这个问题。使用xaml将图像载入silverlight richtextarea

我的问题是,如果我手动重新构建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。

+0

如果我有时间,我想我可以得到符号Silverlight和调试到代码,只是不想花这多少时间就可以了! :( – Andy 2010-12-17 09:44:55

回答

2

RichTextBox上的Xaml属性不支持InlineUIContainer,无论是输入还是输出。

一个解决我会尝试首先是使用XamlReader您的XAML,而不是然后将结果添加到收藏RichTextBox.Blocks -

Section section = (Section)XamlReader.Load(yourXaml); 
yourRTB.Blocks.Add(section); 
+0

这也行不通,因为XamlReader会出现同样的错误。 – 2010-12-17 12:58:35

+0

哇,赶紧!:)我发布时没有看到您的回复! @Akash Xaml读者确实很有用! :) – Andy 2010-12-17 13:31:16

+0

谢谢。非常好。 – 2012-01-25 13:50:19

0

好吧,我已经找到一种方法来做到这一点,所有的 - 不会将XAML直接加载到使用XAML属性的RTB中。

 // Load up the XAML using the XamlReader 
     Object o = XamlReader.Load(xamlTb.Text); 
     if (o is Section) 
     { 
      // Make sure its a section and clear out the old stuff in the rtb 
      Section s = o as Section; 
      rtb.Blocks.Clear(); 

      // Remove the blocks from the section first as adding them straight away 
      // to the rtb will throw an exception because they are a child of two controls. 
      List<Block> tempBlocks = new List<Block>(); 
      foreach (Block block in s.Blocks) 
      { 
       tempBlocks.Add(block); 
      } 
      s.Blocks.Clear(); 

      // Add them block by block to the RTB 
      foreach (Block block in tempBlocks) 
      { 
       rtb.Blocks.Add(block); 
      } 
     } 

要与图像到RTB我已经恢复到加载XAML成对象首先使用XamlReader对象,然后一个接一个地添加这些块,按照该代码加载XAML不像我所能帮助的那样整洁,但我猜XAML属性并不解析InlineUIElements。

Andy。

0

在XAML中./desert.jpg源码不起作用。相反,使用这一个

<Image Source="YourNameSpaceBus;component/images/desert.jpg" 
Height="150" Width="200" /> 

这里有两个重要的关键词第一个是你的命名空间ProjectBus

的secondone固定“组件

那么你的ImagePath你需要写。 否则,即使它可以在designtime上显示,有时它在运行时也不起作用。

<Image Source="AHBSBus;component/images/mail.png" Stretch="None" Height="23"> 
</Image> 

希望帮助