Block text entry in a RichTexBox in Silverlight - silverlight

I use a RichTextBox on my website. I just want to put inside it a description text for my home page. How block the text entry ?
This is my code :
<RichTextBox Name="RTBHome" TextWrapping="Wrap" Height="49" >
<Paragraph>
<Run Text="Welcome to FluxCatcher , want to get your tweet, the informations about our favourite website"/>
<LineBreak></LineBreak>
<Run Text="and so much more in the same page ? So let's subscribe now"/>
</Paragraph>
</RichTextBox>

RichTextBlock is what you're after:
http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextblock(v=vs.95).aspx
Represents a control that displays read-only rich text.

Related

Set/change text weight within the Text property of a TextBlock

I would like to be able to change the weight of text (e.g. change from Normal to Bold and back again) within the Text property string of a TextBlock (presumably using some control character set). Is this even possible?
TextBLock.Text creates a single Run, you set custom Inlines instead:
<TextBlock>
Text with <Bold>bold</Bold> within.
<TextBlock>
Obviously it no longer uses the Text property.
Are you talking about something like this?
<TextBlock>
<Run Text="Hey it's Normal Text"/>
<Run Text="Hey it's Bold Text" FontWeight="Bold"/>
<Run Text="Hey it's Colored Text" Foreground="Green"/>
</TextBlock>

Richtextbox: Embedd image and surround with text

I would like to embed an image in an Richtextbox in way that the image is sourrounded by text (should look like a newspaper article which contains some images).
That's what I have until now:
<RichTextBox>
<Paragraph>
<InlineUIContainer>
<Image Source="{Binding Image}" Width="200" Height="100" />
</InlineUIContainer>
<Run Text="{Binding Text}" />
</Paragraph>
</RichTextBox>
This code embedds the image in a way so that the first line of the run starts at the bottom right edge of the image.
But I would like to embedd it such a way:
http://i.stack.imgur.com/NVUNz.jpg
How can this be implemented for WP7.1?
Thanks.
I know this can be done, i believe you would be looking at either Margin or Padding around the image.....As the whole thing will look like an object because that's what it is.
so you want to put Padding or Margin around the image to push the text away from the object giving the appearance of space between the object. Also try Pushing the text to the right and the image to the left.
I hope this will help a little. :)
I don't think it can be done until FlowDocument will be available in Silverlight. Or somebody invents a similar control.

Silverlight text around an image

Im am trying to wrap text around an image as one would use the html float property. Is there a way to acomplish this in silverlight 3?
Thanks
I tackled this issue a while back. There is not really a good way that I know of. This will work though it's just painful.
In order to simplify the explanation why don't we assume that the image is in the upper right corner of the page and the text needs to be to the left and below the image.
Start by placing the TextBlock and the Image side-by-side.
Calculate the bottom most point of the TextBlock and the bottom most point of the image. (Use their top margins and actual heights.
While the TextBlock is the larger you move a word at a time into a newly created TextBlock below the image. This creates the illusion of wrapping text.
leftText.Text = textToWrap;
bottomText.Text = string.Empty;
Stack<string> wordsToMove = new Stack<string>();
double imageBottomPoint = image1.ActualHeight + image1.Margin.Top;
while ((leftText.ActualHeight + leftText.Margin.Top) > (imageBottomPoint + 14))
{
int lastSpace = leftText.Text.LastIndexOf(' ');
string textToMove = leftText.Text.Substring(lastSpace).Trim();
BlockedText.Text = leftText.Text.Remove(lastSpace);
wordsToMove.Push(textToMove + ' ');
}
StringBuilder sb = new StringBuilder(bottomText.Text);
while (wordsToMove.Count > 0)
{
sb.Append(wordsToMove.Pop());
}
bottomText.Text = sb.ToString();
You need to look RichTextBox and FlowDocument if it is WPF and RichTextBox if Silverlight 4.0.
Silverlight 4.0 Solution
<RichTextBox TextWrapping="Wrap" IsReadOnly="False">
<Paragraph>
More text here ..
<InlineUIContainer>
<Image Source="abc.jpg"/>
</InlineUIContainer>
more and more text here;
<LineBreak />
</Paragraph>
</RichTextBox>
WPF Solution-
<RichTextBox>
<FlowDocument IsEnabled="true">
<Paragraph>
Text text ..
<Button Margin="10,0,10,0" Content="A Button Float"/>
More text..
</Paragraph>
<Paragraph TextAlignment="Center">
<Image Source="abc.jpg"/>
text text..
</Paragraph>
</FlowDocument>
</RichTextBox>

WPF/XAML: Typography.Capitals seems to have no effect

All of these bits of text look the same, but I am trying to get them to look different. I want small caps text. What am I missing here to get the small caps typography effect to work?
To reproduce this, open Visual Studio 2008, Do File|New Project, create a new Windows|WPF application, paste the mark-up below into Window1.xaml, then run it.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<FlowDocumentReader>
<FlowDocument>
<Paragraph>
<Run>Some text</Run> <LineBreak />
<Run Typography.Capitals="SmallCaps">Some text</Run> <LineBreak />
<Run Typography.Capitals="AllSmallCaps">Some text</Run> <LineBreak />
<Run Typography.Capitals="PetiteCaps">Some text</Run> <LineBreak />
<Run Typography.Capitals="AllPetiteCaps">Some text</Run> <LineBreak />
</Paragraph>
</FlowDocument>
</FlowDocumentReader>
</Grid>
</Window>
Based on the first answer, it seems that if you specify a particular font, you can get somewhere. Change the FlowDocument start tag to:
<FlowDocument FontFamily="Palatino Linotype">
.. and you get SmallCaps and AllSmallCaps, but not PetiteCaps or AllPetiteCaps. So it depends on the font. But this gives rise to other questions:
Why doesn't the default font (which looks a lot like Times New Roman) support these?
Do other widely used fonts (e.g. the local Courier New equivalent) support these?
Is there a list of which fonts support what?
What percentage of fonts will support this - most, some, or few?
Can you determine in code what the font supports - if this is the case, I could fake the AllSmallCaps - e.g. by converting the text to all capitals and scaling by 80%. But not SmallCaps.
This only works with specific OpenType fonts - the example in Help uses Pescadero which is in the Open Type Sample. Even then, only SmallCaps and AllSmallCaps are supported.
I noticed that default font with a "bold" fontweight does render the SmallCaps properly:
<StackPanel>
<TextBlock Typography.Capitals="SmallCaps" FontFamily="Pescadero" Padding="2">2pm</TextBlock>
<TextBlock Typography.Capitals="SmallCaps" FontWeight="Bold" Padding="2">2pm</TextBlock>
</StackPanel>

WPF RichTextBox - spell check does not work with formatted text

If I define a RichTextBox as follows;
<RichTextBox SpellCheck.IsEnabled="True">
<FlowDocument />
</RichTextBox>
When I type in the work 'Sample' and make the first three letters bold, the spell checker underlines the word.
The source XAML of the document shows that the RichTextBox is splitting the word into two seperate runs;
<Paragraph>
<Run FontWeight="Bold" xml:lang="en-gb">Sam</Run>
<Run xml:lang="en-gb">ple</Run>
</Paragraph>
If I manually contruct a document with the following blocks;
<FlowDocument>
<Paragraph>
<Run FontWeight="Bold">Sam</Run>ple
</Paragraph>
</FlowDocument>
The spell checker passed the word successfully.
Has anyone come across this before? Is there a workaround that I can use?
Thanks
Matt
There seem to be issues with the spell checker and different locales.
If I start with this:
<RichTextBox SpellCheck.IsEnabled="True" xml:lang="en-GB">
<FlowDocument />
</RichTextBox>
I can reproduce your error (by typing "Sample" and bolding the "Sam"), but not with this:
<RichTextBox SpellCheck.IsEnabled="True">
<FlowDocument />
</RichTextBox>
Someone has a similar problem here. Microsoft replies:
This problem occurs because the Language property on FrameworkElement (and thus TextBox/RichTextBox) defaults to "en-US", and you are using the "en-NZ" locale. When you type text into TextBox/RichTextBox, it will be in a different locale than the text set in XAML. The spell checker does not cross language boundaries, which results in the behavior you see.

Resources