How can I stop text block Wrapping When this line is full? - wpf

In my wpf application, I have added a text block control and set its value with Chinese and English text. But it wraps and I don't want it to wrap.
How can I resolve this problem?

Add "TextBlock.TextAlignment Property" Like
<TextBlock Name="tbllist" Text="Your text" TextWrapping="Wrap" TextAlignment="Justify"/>

Related

Silverlight TextBlock should wrap whole words only

I have multiple TextBlocks in a control. The blocks have a fixed width and the TextWrap property is set to Wrap. The text is provided via binding.
Right now the wrapping occurs when SL detects that it can't fit another character in the line. Which results in something like "The quick bro" \r\n "wn fox jumps".
But I want those blocks to wrap their text only at word boundaries and not at some random position in the middle of a word. The expected outcome should look something like "The quick brown" \r\n "fox jumps".
This is the XAML for one of the TextBlocks:
<TextBlock
x:Name="Foo"
Foreground="#FFD4E4FF"
FontSize="14.667"
FontFamily="Arial"
Canvas.Left="586.671"
LineHeight="23.707"
TextWrapping="Wrap"
Text="{Binding Bar}"
Canvas.Top="170"
Width="120" />
Any ideas?
We finally found the problem. For some reason the strings we loaded from the database contained characters that looked like regular blanks in the debugger and in text editors but where not treated as such by Silverlight. The character in question was a non-breaking space

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>

TextBox Partially Editable

Is it possible to make the contents of a TextBox or a RichTextBox parially editable? For instance, I would like to have something that looks like the following:
<TextBox TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" FontFamily="Courier New" Margin="10,0">
This text and anything before it isn't editable.
This Text is Editable
This text and anything after it is not editable.
</TextBox>
or something like this:
<RichTextBox AcceptsReturn="True" VerticalScrollBarVisibility="Auto" FontFamily="Courier New" Margin="10,0">
<FlowDocument>
<Paragraph>This text and anything before it is not editable.</Paragraph>
<Paragraph>This text is editable.</Paragraph>
<Paragraph>This text and anything after it is not editable.</Paragraph>
</FlowDocument>
</RichTextBox>
Ideally, I would be able to style the editable text different than the uneditable text. Before anybody tells me I shouldn't do this, I have a valid reason for doing it.
Thanks in advance.
You should be able to encapsulate the three controls into a scrollable region and resize your editable field as needed (i.e., the editable field has no scrolling, only the containing region).
It's not very pretty, especially if there isn't an easy way of doing it with XAML (I've never used it, so I can't say), but I would content it's far better than trying to hack this thing into (Rich)TextBox.
A textBox with its Template overrriden to hide its border and 2 textblocks of same look and feel put ahead and post the textbox in that Template can achieve what you seek.
Default textbox template which you can override is here...

WPF show small number beside all Controls

I have many FrameworkElements (TextBlock, CheckBox, ListBox..) and I would like to make something allowing me to show a small number besides every one control.
Some text ³
I came with the idea to write a MarkupExtension, where I could write that number like this:
..
<TextBlock Text="Some Text" SomeExtension="3" />
..
and then to add it somehow to the template of the Control.
But I'm sure, you guys have better solution for this problem ;)
One way to go with it would be create a Attached Property. Upon setting it on a control, a custom Adorner would be added for that control showing specified number.
Use the tag property to provide the number you want and inside the custom template databind to the property
<TextBlock Text="Some Text" Tag="3" />
and inside the controltemplate
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Tag}"/>

WPF: Use SpellCheck On Read-Only TextBox

I'm looking to display text with the wavey red lines where a word is misspelt, but I only want the text to be selectable, not editable. If I set the TextBox's IsReadOnly property to True or IsEnabled to False, the wavey red lines disappear and I can't get around it by putting something transparent as this will prevent the user being able to select sections of the text.
Is there anyway I can keep the red lines, allow the text to be selectable but prevent the actual text being modified?
Thanks
You could hook up to on the text change event of the text box, and just reject the new text. It would have the same effect of readonly without graying out the textbox or getting rid of the spell checking.
Thanks David. I'm currently looking at 2 possible solutions, yours and the following:
I've created a custom control which is based on the standard TextBox, but effectively has 2 textboxes laid on top of one another in this manor:
<TextBox Name="tbxBack"
Foreground="Transparent"
SpellCheck.IsEnabled="True"
TextWrapping="Wrap"
SnapsToDevicePixels="True"/>
<TextBox Name="tbxFront"
Background="Transparent"
TextWrapping="Wrap"
SnapsToDevicePixels="True"
IsReadOnly="True"/>
I think it's pretty straight forward what's going on here, but I'm concerned about the potential overhead this will cause.
The reason I'm looking into the double TextBox solution is that I'm worried if I try and cancel the event, it could end up with some sort of flashing in the control when the text is changed.

Resources