Silverlight 4 RichTextBox 使用 DataContext 绑定数据
我正在使用 Silverlight 4 并尝试将我的测试应用程序设置为多语言,但当我到达“RichTextBox”控件时遇到一些麻烦。我可以通过执行后台代码(c#)来正确绑定它,但是当尝试使用“DataContext”属性时,我根本无法加载它。
我创建了一个 FormatConverter,它返回一个用于测试的块(段落),我的 RichTextBox 代码如下所示:
<RichTextBox x:Name="rtaTest" BorderThickness="0" IsReadOnly="True" UseLayoutRounding="True"
DataContext="{Binding Source={StaticResource Localization}, Path=Home.MainContent, Converter={StaticResource ParagraphFormatConverter}}">
</RichTextBox>
我想知道是否有一种从 XAML 绑定 RichTextBox 的方法。
I am working with Silverlight 4 and trying to put my test apps multilingual but I am having some trouble when I arrive to the "RichTextBox" control. I am able to bind it properly by doing back-code (c#), but when trying using the "DataContext" attributes I am not able to load it at all.
I have created a FormatConverter that return a Block (paragraph) for testing and my code where I have my RichTextBox looks like:
<RichTextBox x:Name="rtaTest" BorderThickness="0" IsReadOnly="True" UseLayoutRounding="True"
DataContext="{Binding Source={StaticResource Localization}, Path=Home.MainContent, Converter={StaticResource ParagraphFormatConverter}}">
</RichTextBox>
I am wondering if there is a way of binding a RichTextBox from the XAML.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Run 似乎支持 SL4 中的数据绑定,如下所示:
Run seems to support databinding in SL4, as in:
我想您可能对 DataContext 的使用有点困惑。例如,您可能有一些富文本,其中一个或多个
InlineUIContainer
元素的某些子元素可能会从某个对象的属性中检索其文本。您可以将该对象分配给DataContext
。虽然我不太确定您期望实现什么,但我怀疑您真正需要的是转换器实际返回一个
BlocksCollection
(即使它只包含单个Block< /code> 你最初返回)然后绑定为:-
I think you may be a little confused about the used of the DataContext. You might for example have some Rich text where some children of one or more
InlineUIContainer
elements may retrieve their text from a property of some object. You would assign the object to theDataContext
.Whilst I'm not quite sure what you were expecting to achieve but I suspect that what you really need is for your converter to actually return a
BlocksCollection
(even if it just contains the singleBlock
you were originaly returning) and then to bind as:-这个 FillFromXml 是 WPF 的东西吗?在 Silverlight 中看不到它。
This FillFromXml is a WPF thing? Don't see it in Silverlight.
块无法设置,只能获取。为
RichTextArea
设置块的一种方法是Blocks cannot be set, they can only be fetched. One way to set the blocks for a
RichTextArea
is