Silverlight 4 RichTextBox Bind Data using DataContext
Solution 1
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 the DataContext
.
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 single Block
you were originaly returning) and then to bind as:-
<RichTextArea x:Name="rtaTest" BorderThickness="0" IsReadOnly="True"
UseLayoutRounding="True"
Blocks="{Binding Source={StaticResource Localization},
Path=Home.MainContent, Converter={StaticResource ParagraphFormatConverter}}" />
Solution 2
Run seems to support databinding in SL4, as in:
<RichTextBox>
<Paragraph>
<Run Text="{Binding Path=LineFormatted}" />
</Paragraph>
</RichTextBox>
Solution 3
This FillFromXml is a WPF thing? Don't see it in Silverlight.
Nordes
I am a developer. I am able to do pretty much everything, but what I loves to do is C# (.Net) and JavaScript (Using NodeJS + VS Code). After working in Montreal (Canada), Bordeaux (France) and Maastricht (Netherlands), now I work in Osaka (Japan). In my career I was involved at all the level of software design and architecture. I've also managed development teams and been a Team Lead for a few years. I currently work in a R&D group in order to build the PoC and much more. I like to play with a lot of technologies and I still am saying that I never know enough. ;)
Updated on June 05, 2022Comments
-
Nordes almost 2 years
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.
-
Ignacio Soler Garcia almost 11 yearsAmazing, you made my day ;)