I have a label. As the content I want to set the infinity symbol. How can I achieve that?
<Label Content="∞" ... />
FYI: XML Character Entities and XAML
Like this:
<Label Content="∞"/>
The infinity symbol is represented by the unicode character 221e. If you follow the link it shows fonts that support the character. It seems like most popular fonts do, including Arial, which I think is the default font for labels.
Somethig like this (might need to specify size of the image):
<Label>
<Label.Content>
<Image Source="URI to Image"/>
</Label.Content>
</Label>
Edit: Since you posted a picture i assumed you have an image, if you want the symbol as text say so.
See here: http://www.fileformat.info/info/unicode/char/221e/index.htm
Related
I have a TextBox defined like this:
<TextBox Text="{Binding License.LicenseKey}"
HorizontalContentAlignment="Left"
TextAlignment="Justify"
Width="350"
Height="100"
Margin="10,0,0,0"
TextWrapping="Wrap" />
Currently a long string will break on special characters:
I would prefer it to simply break on any character once it reaches the end of the TextBox like this:
Is there a way to disable the stock breaking that a TextBox uses? I have tried various options for TextAlignment and HorizontalContentAlignment to no avail.
You could add a zero-width space (U+200B) after each character which would allow a break at any position. You would need to define a property in your view model and bind to it, and have the getter do this transformation so that it is displayed with line breaks, e.g.:
string SomeProperty
{
get { return String.Join(string.Empty, License.LicenseKey.Zip(new string('\u200B', License.LicenseKey.Length), (x, y) => x.ToString() + y)); }
set { Model.LicenseKey = value?.Replace("\u200B", string.Empty); }
}
However I don't know what would happen to the cursor position.
This is exceptionally messy due to limited options on the TextBox's TextWrapping property.
See this forum post to explain the U+200B comment below your question. However, that doesn't work for you because you DON'T want it to break. And if there's a library of standard non-breaking versions of characters, I've been unable to dig it up.
The only way I see this working is to use a fixed-width font, keeping track of how many characters are entered alongside the capacity of the box, and adding your own newline when that capacity is reached.
I am trying to put some formatted text in a view (an imprint, for what it's worth) with a Label with an formatted text. Text formatting works as intended, but whenever I try to add whitespace characters to the end of a span element within the formatted text these appear to be trimmed. This holds true for normal spaces, non-breaking spaces and CR/NL so far. Anyway, when in the middle of a string, nothing is removed.
This renders the label unusable for me (at least for this use-case), since I won't be able to format my text properly. Is there anything I have missed? I did not find anything about this matter in the web and in the documentation. Is the approach taken completely wrong, or is this a bug in Xamarin? (For that matter, the version used is 2.3.2.127)
This renders the label unusable for me (at least for this use-case), since I won't be able to format my text properly
It's not entirely clear why you would try to achieve this formatting with trailing whitespace.
Have you tried using margin or padding around the label?
https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/margin-and-padding/
Using whitespace characters for element spacing is generally not a good practice.
The solution to this is to use inline Text="..." rather than enclosing the text between an opening and closing tag. For example, this preserves the spaces:
<FormattedString.Spans>
<Span Text="You have " />
<Span Text="{Binding Points}" />
<Span Text=" points." />
</FormattedString.Spans>
But this trims whitespace:
<FormattedString.Spans>
<Span>You have </Span>
<Span Text="{Binding Points}" />
<Span> points.</Span>
</FormattedString.Spans>
Is there a way to use inline formatting (like Swing's HTML tagging within labels) with WPF? I could not find any documentation.
The TextBlock (there may be others) can make use of several inline formatting elements.
[example lifted verbatim from: http://wpf.2000things.com/2011/03/14/245-easily-inline-text-formatting-codes-with-textblock-control ]
<TextBlock Margin="10" Height="100" FontSize="14" Width="290" TextWrapping="Wrap">
We <Bold>few</Bold>, we happy <Bold>few</Bold>, we band of <Underline>brothers</Underline>;
For he to-day that sheds his <Italic>blood</Italic> with me
Shall be my <Underline>brother</Underline>; be he ne'er so <Italic>vile</Italic>,
This day shall <Bold>gentle</Bold> his <Italic>condition</Italic>;"
</TextBlock>
Not quite sure if this is what you're looking for, but XAML uses attributes. Just like in HTML you can say <element attribute="foo"></element>
I'm really stumped on how to go about binding fonts to a textbox. I'd like for my user to be able to choose between 3-4 different fonts. I have something like this right now:
<TextBox x:Name="MyTextBox" AcceptsReturn="True" FontSize="20"
FontFamily="{Binding FontSelection}" />
But I have no clue how the c# should look, and I had no luck googling for it. What is the best way to do this? Do I have to create an observable collection? I've tried adding fonts to the Application.Resources, but it wouldn't let me.
Thanks for any answers!
This FontSelection property has to be single item. You could first try simple valid string (like 'Arial'), it could work. Another approach is FontFamily type as poined out by Romasz.
Also there are Converters available, quite easy to implement. http://channel9.msdn.com/Series/Windows-Phone-8-1-Development-for-Absolute-Beginners/Part-25-Advanced-Binding-with-Value-Converters With this you could save user font selection as simple number for example and convert it to appropriate type with Converter.
I have a TextBlock I would like to pass a property of 'LineSpacing'. The thing with using "LineHeight" with LineStackingStrategy="BlockLineHeight" is that it also applies the LineHeight to the segment before the first line:
How can I manage to preserve said 'LineSpacing' without modifying the LineHeight before the first line?
One thing I though might work is to separate each line in a Paragraph of a FlowDocument, since the Paragraph has a property Spacing Before Line and Spacing After Line.
Any help would be truly appreciated. Thanks in advance.
ANSWER
It seems that you can use LineStackingStrategy="MaxHeight" to avoid having leading on the first line. (Check answers below for full details).
P.S. Thanks to Mitch for the revelation :D
It seems that you can use LineStackingStrategy="MaxHeight" to avoid having leading on the first line:
<TextBlock LineStackingStrategy="MaxHeight" TextWrapping="Wrap" LineHeight="50">Lorem...</TextBlock>
Produces