WP 8.1 text scaling - c#

So say I have a textblock with a fontsize 32. The value of the text property is a variable amount of characters. If the text at a fontsize of 32 is cut off, how could i down scale the fontsize until the total width of the textblock is equal to the page width?
-I'd post a screenshot but not enough rep :/

The best solution is insert the TextBlock inside a fix width ViewBox:
<Viewbox Width="300" StretchDirection="Both" >
<TextBlock x:Name="testblock" Foreground="Magenta" FontSize="24" Text="This is a test"/>
</Viewbox>
And that will make the job without any effort. Change the parameters depending you need, and you can insert the textblock inside a border,etc.

Related

Calculated Binding in net maui

is there an easy way to use a calculated property in a view?
I need to give a left padding proportional to an actual width of a grid, or the width of a column.
For example if I tilt the phone the grid gets wider and I want to update the padding.
This seems to work, but I want to calculate a value from the width, for example width/50:
<Label Text="Seg"
Style="{StaticResource subTitleLightTextStyle}"
Grid.Row="1"
Padding="{Binding Source={x:Reference bodyCalendar},
Path=Width}"
Grid.Column="1" />

Remove WPF FlowDocument left padding?

I'm attempting to align a flow document to the left with no padding, so that it matches exactly what you see in a TextBlock. I've recreated a simple example of what I'm basically trying to achieve. Here's what I have so far:
<Grid>
<TextBlock Foreground="Red" Height="Auto" TextWrapping="Wrap"
Margin="0" Padding="0" FontSize="50" FontFamily="Arial"
Text="Some text."/>
<RichTextBox BorderThickness="0" Background="Transparent" BorderBrush="Transparent" IsInactiveSelectionHighlightEnabled="False" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled"
Height="Auto"
Margin="0" Padding="0" FontSize="50" FontFamily="Arial" >
<FlowDocument PagePadding="0" LineStackingStrategy="BlockLineHeight">
<Paragraph Margin="0" Padding="0" TextIndent="0">Some text.</Paragraph>
</FlowDocument>
</RichTextBox>
</Grid>
Here's the result:
As you can see, the red is the TextBlock version and the black is the RichTextBox/FlowDocument version. The FlowDocument text is offset by about 5 pixels to the right. I've tried to remove all padding that I am aware of, but I still can't get rid of that offset. Any help is appreciated.
NOTE: This question is found as duplicate of WPF: How to make RichTextBox look like TextBlock?
This offset is related to the caret implementation in the RichTextBox control.
Look at .Net 4.8 source, in the RichTextBox.cs file:
// Allocates the initial render scope for this control.
internal override FrameworkElement CreateRenderScope()
{
FlowDocumentView renderScope = new FlowDocumentView();
renderScope.Document = this.Document;
// Set a margin so that the BiDi Or Italic caret has room to render at the edges of content.
// Otherwise, anti-aliasing or italic causes the caret to be partially clipped.
renderScope.Document.PagePadding = new Thickness(CaretElement.CaretPaddingWidth, 0, CaretElement.CaretPaddingWidth, 0);
// We want current style to ignore all properties from theme style for renderScope.
renderScope.OverridesDefaultStyle = true;
return renderScope;
}
And the CaretElement.CaretPaddingWidth definition in the CaretElement.cs file:
// Caret padding width to ensure the visible caret for Bidi and Italic.
// Control(TextBox/RichTextBox) must have the enough padding to display
// BiDi and Italic caret indicator.
internal const double CaretPaddingWidth = 5.0;
Therefore, the only option that you can check is set the RichTextBox margin to Margin="-5,0,0,0".

TextBox how to make it stand out from bitmap below

I have a textBox on an image stacked one above the other.
The image may vary and so the text may be hidden by the colour below.
I am searching for an effect like the one in the pic
so that whatever the background light or dark the image stands always out.
I've tried dropshadow or blur effect but didn't work or didn't managed to make it work effectively.
You can change your Fontfamily, Fontsize , Stroke as your wish and the OutlinedTextBlock class is in Apply stroke to a textblock in WPF. Make sure you have implemented the namespace of OutlinedTextBlock
<local:OutlinedTextBlock FontFamily="Verdana" FontSize="28pt" FontWeight="ExtraBold" TextWrapping="Wrap" StrokeThickness="1" Stroke="Black" Fill="White">
Text
</local:OutlinedTextBlock>

RichTextBox in Windows Phone 8 cuts long content

I have next XAML:
<ScrollViewer Height="Auto">
<RichTextBox VerticalScrollBarVisibility="Visible">
<Paragraph>
Lorem ipsum ....
</Paragraph>
</RichTextBox>
</ScrollViewer>
If you set very long text to a paragraph, lets say 10000+ bytes long - displayed content is cut even though the control height is ok:
How to make it render content correctly?
Information here. Apparently, the max size height on a control is 4096 px.

How to change font size in TextBlock, when the text is in the second line

I'm looking for method to change font size in TextBlock if text goes to second line.
How can I know, when the text proceed to the second line?
Thanks for help.
What you could do is handle the TextChanged event and in the handler check the length of the text.
If the text is <= 20 you keep the original size. If it's > 20 but <= 25 you decrease the font size by say 3 points. An so on until you reach a limit of characters you want to support, say 50 or something.
You will probably need to disable Textbox text wrapping so that you only have a single line of text.
Wrapping with a Viewbox may give you the functionality you're after:
<Viewbox Stretch="Uniform" Width="50" Height="50">
<TextBlock Text="Test" />
</Viewbox>
source - https://stackoverflow.com/a/13268895/1202600

Categories

Resources