textblock

Set TextBlock to preserve white space at the beginning and at the end?

一笑奈何 提交于 2019-12-03 11:09:02
问题 EDIT: The code below actually works as I want - this question a little misleading. Please ignore it. Normally when I set Text property of TextBlock like this: TextBlock tb = new TextBlock(); tb.Text = " Hello World "; The whitespace at the beginning and at the end of text are not shown. The text shown by TextBlock is only Hello World . How can I set TextBlock to display them (i.e., not remove the whitespace)? Am I missing some property? 回答1: In this case you don't need to use xml:space=

WPF TextBlock Color for each Character

只谈情不闲聊 提交于 2019-12-03 10:51:27
how to get each character of a textblock of different color in wpf? Use many different runs : <TextBlock FontSize="22"> <Run Foreground="Gold">H</Run> <Run Foreground="Maroon">e</Run> <Run Foreground="Blue">l</Run> <Run Foreground="Orange">l</Run> <Run Foreground="Brown">o</Run> </TextBlock> This produce the result: You can compose colors by adding each color as a new textbook for example: TextBlock printTextBlock = new TextBlock(); printTextBlock.Foreground = Brushes.Red; printTextBlock.Text = "This text will colored with red"; StackPanel.Children.Add(printTextBlock); The same for the rest of

Maximum number of lines for a Wrap TextBlock

亡梦爱人 提交于 2019-12-03 10:47:29
问题 I have a TextBlock with the following setting: TextWrapping="Wrap" Can I determine the maximum number of lines? for example consider the following string TextBlock.Text : This is a very good horse under the blackboard!! It currently has been shows like this: This is a very good horse under the blackboard!! I need that to become something like: This is a very good horse ... any solution? 回答1: Update (for UWP) In UWP Apps you don't need this and can use the TextBlock property MaxLines (see MSDN

How to make the text bold of TextBlock in Silverlight?

允我心安 提交于 2019-12-03 09:38:39
问题 I am developing window phone 7 application in C#. I am new to the window phone 7 application. I am also new to the silverlight. I want to generate the bold text of Texblock dynamically. I want to generate the bold text only for some part of the text. I am using the following code IncometextBlock.Text = "Income entries on " + selectedDate.ToShortDateString() + " Page - "+SelectedButtonName+""; I want the output as " Income entries on 21/01/2011 Page - A " I want the above output. How to make

WPF Textblock, linebreak in Text attribute

[亡魂溺海] 提交于 2019-12-03 08:52:19
问题 Is there a way to have \n make a line break in a TextBlock ? <TextBlock Text="line1\nLine2" /> Or is there a better way to force a middle line break, inside the Text attribute? <LineBreak /> This doesn't work for me, it needs to be the value of the Text attribute, because the text string is being set from an outside source. I'm familiar with LineBreak but it's not the answer I'm looking for. 回答1: I know this is ressurecting an old question, but I had the same problem. The solution for me was

WPF Multiline TextBlock CenterAlignment Issue [duplicate]

删除回忆录丶 提交于 2019-12-03 04:11:51
This question already has an answer here : TextBlock.TextWrapping - how to make the text wrap so that the lines are center-aligned? (1 answer) I'm having an issue with multiline text blocks where it is not center aligning properly The text is coming like abcde\nabc This comes out abcde abc What I want is abcde abc This seems a simple thing and I would have thought that the textblock would center align like that automatically but it does not seem to. Try the TextAlignment property instead of HorizontalAlignment . First one is the alignment of text in the TextBlock , second the alignment of the

Maximum number of lines for a Wrap TextBlock

自闭症网瘾萝莉.ら 提交于 2019-12-03 01:16:10
I have a TextBlock with the following setting: TextWrapping="Wrap" Can I determine the maximum number of lines? for example consider the following string TextBlock.Text : This is a very good horse under the blackboard!! It currently has been shows like this: This is a very good horse under the blackboard!! I need that to become something like: This is a very good horse ... any solution? Update (for UWP) In UWP Apps you don't need this and can use the TextBlock property MaxLines (see MSDN ) Original Answer: If you have a specific LineHeight you can calculate the maximum height for the TextBlock

WPF Textblock, linebreak in Text attribute

南楼画角 提交于 2019-12-03 00:52:32
Is there a way to have \n make a line break in a TextBlock ? <TextBlock Text="line1\nLine2" /> Or is there a better way to force a middle line break, inside the Text attribute? <LineBreak /> This doesn't work for me, it needs to be the value of the Text attribute, because the text string is being set from an outside source. I'm familiar with LineBreak but it's not the answer I'm looking for. Noaki I know this is ressurecting an old question, but I had the same problem. The solution for me was to use HTML encoded line feeds ( &#10; ). Line1&#10;Line2 Looks like Line1 Line2 For more of the HTML

How to make the text bold of TextBlock in Silverlight?

谁说我不能喝 提交于 2019-12-03 00:08:52
I am developing window phone 7 application in C#. I am new to the window phone 7 application. I am also new to the silverlight. I want to generate the bold text of Texblock dynamically. I want to generate the bold text only for some part of the text. I am using the following code IncometextBlock.Text = "Income entries on " + selectedDate.ToShortDateString() + " Page - "+SelectedButtonName+""; I want the output as " Income entries on 21/01/2011 Page - A " I want the above output. How to make the bold text for above requirement ? Can you please provide me any code or link through which I can

Xaml TextBlock set round corner

半世苍凉 提交于 2019-12-02 22:14:05
I am trying to set rounded corner of TextBlock in xaml . But there is no such property. <Grid x:Name="grdDis" Grid.Row="1"> <TextBlock Text="Description" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Name="txtDescription" Margin="18,10,0,0" Height="128" Width="445"/> </Grid> How can I set rounded corner of TextBlock. And also want to set Background color of TextBlock. Use Border : <Border Margin="5" Padding="5" BorderThickness="1" BorderBrush="Red" Background="AntiqueWhite" CornerRadius="10"> <TextBlock Text="Lorem ipsum"/> </Border> for that use the Border element as