Could anyone please let me know how I can display numbers like 100 to 10², with base 10 raised to the power of "n". The base-10 numbers are dynamic, so I cannot rely on the ASCII coding.
This is for a C# based WPF application.
You can use the Superscript value on the Run.BaselineAlignment property:
<TextBlock FontSize="14">
<Run Text="25" /><Run Text="2" FontSize="8" BaselineAlignment="Superscript" />
</TextBlock>
You can also data bind to the Run.Text property if you prefer:
<TextBlock FontSize="14">
<Run Text="{Binding Number}" /><Run Text="{Binding Power}" FontSize="8"
BaselineAlignment="Superscript" />
</TextBlock>
Also using this method, you can set the various properties individually on the number and the power, so you can get the exact look that you want.
Related
How can I do this with my current implementation ? My last option would be to use a StackPanel as it would involve changing a lot of other things . Any other workarounds would be appreciated.Image below .Incase it is not clear from the image :
In one straight line,
Extreme Left aligned : Apparels (count of defects)
Extreme Right aligned : Nearby outlets ( Count of nearby outlets)
Things I tried :
The flowDirection Property in RUn : did not work
Properties like alignment/orientation that are generally there for other controls don't seem to be there for Run.
<TextBlock
Grid.Column="0"
TextTrimming="CharacterEllipsis"
VerticalAlignment="Center">
<Run Text="{Binding Mode=OneWay, Converter={StaticResource Converter1}}" />
<Run Text="{Binding Defects, Converter={StaticResource Converter2}, Mode=OneWay}" />
<Run Text="{Binding Outlets, Converter={StaticResource Converter3}}" />
</TextBlock>
I'm trying to bind two <Run>s inside a TextBlock as shown in the snippet below. But I'm getting an XamlParseException.
Basically I'm trying to achieve this format:
CodeNum: LongDescription
If the below code is doomed to fail what other alternatives do I have?
<TextBlock>
<Run FontWeight="Bold" Text="{Binding CodeNum}"/>
<Run FontWeight="Bold" Text=": "/>
<Run Text="{Binding LongDescription}"/>
</TextBlock>
I'm guessing that either LongDescription or CodeNumis is a read-only property (doesn't have public setter). You need to change binding to be one way for all read-only properties that you use in Run
<Run Text="{Binding LongDescription, Mode=OneWay}"/>
I have TextBlock in which I put 2 Inlines (Runs), the HorizontalAlignment of the TextBlock is set to Center, this is ok, I just want to center the first Run comparing to the second, here's my code :
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="/Throne;component/Fonts/#Segoe UI Light" FontSize="35" FontWeight="Bold" Visibility="{Binding UserNameTextBlockVisibility}">
<Run FontSize="25">En tant que :</Run>
<LineBreak />
<Run Text="{Binding UserName}" Foreground="ForestGreen"/>
</TextBlock>
Here's the result I get :
What I want to achieve :
I tried to search around the documentation and in threads on the internet, but I didn't really find a way to achieve this, how can I realize that ?
Set TextAlignment="Center" on your TextBlock
<TextBlock TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="/Throne;component/Fonts/#Segoe UI Light" FontSize="35" FontWeight="Bold" Visibility="{Binding UserNameTextBlockVisibility}">
<Run FontSize="25">En tant que :</Run>
<LineBreak />
<Run Text="{Binding UserName}" Foreground="ForestGreen"/>
</TextBlock>
I am trying to make a single block of text composed of multiple TextBlocks
- THE TARGET
For example, I want to achieve like the line below:
"I read this line in a ListBox, notice the multiple text formatting"
The way I'm trying to do is
<StcakPanel Orientation="Horizontal" Width="400" >
<TextBlock Text="I read this line in a " TextWrapping="Wrap" />
<TextBlock Text="ListBox" FontStyle="Italic" TextWrapping="Wrap"/>
<TextBlock Text=", notice the multiple " TextWrapping="Wrap" />
<TextBlock Text="text formatting" FontWeight="Bold" TextWrapping="Wrap"/>
<StcakPanel>
- THE PROBLEM
The text does not fit in the StackPanel, despite of setting TextWrapping for TextBlocks and Width for StackPanel.
I want to generate this code at runtime. I don't know how many words do I need to format.
Kind of showing SearchResults with highlighted search keywords.
- THE QUESTION
How can the above target be achieved either using StackPanel or something else? Having the following constraints.
The text length is unknown
The number of textblocks in the stackpanel is unknown
width and height is Unknown
Thanks very much
You should use a single <TextBlock> which can contain multiple <Run>s that can each have their own formatting. If you want to insert a linebreak, you can use the <Linebreak /> control.
<StackPanel Orientation="Horizontal" Width="400" >
<TextBlock>
<Run Text="I read this line in a" />
<Run Text="ListBox" FontStyle="Italic" />
<Run Text=", notice the multiple" />
<Run Text="text formatting" FontWeight="Bold" />
</TextBlock>
<StackPanel>
At that point you probably don't even need the <StackPanel> unless you are going to have multiple <TextBlocks> stacked on top of one another.
See this post for more information and examples: http://www.danderson.me/posts/working-with-the-wpf-textblock-control/
To databind multiple runs within a TextBlock, see this answer: Databinding TextBlock Runs in Silverlight / WP7
I want to 1. from the following image:
My code is here:
<WrapPanel>
<TextBlock Text="Title: " Style="{StaticResource Title}" TextWrapping="Wrap" />
<TextBlock Text="{Binding Description" Style="{StaticResource Normal}" TextWrapping="Wrap" />
</WrapPanel>
But if Description text is short, shown like 2., if Description text is long, shown like 3.
How to do this like 1.?
I have solve my question using Run:
<TextBlock TextWrapping="Wrap">
<Run Text="Title: " Style="{StaticResource TitleRun}"/>
<Run Text="{Binding Description,Mode=OneWay}" Style="{StaticResource NormalRun}"/>
</TextBlock>
Just keep adding them to the Grid with 2 columns and n number of rows, adding new rows/colls as you add them.
You can create a behaviour for that.