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>
Related
I have a WPF project with an XamDatagrid that utilizes clipboard operations. I am currently allowing a user to paste a decimal into the grid, but when the user pastes in a decimal with a comma - example: 1,234.987 - I get an error saying "Unable to convert the value to the destination type, value 1,234.987 is not a valid number". However, when pasting in 1234.987, I have zero issues. How do I allow for the comma???
<igDp:XamDataGrid.FieldLayouts>
<igDp:FieldLayout >
<igDp:FieldLayout.Fields>
<igDp:Field Name="Field1" Label="Field1" Width="100" AllowEdit="False"></igDp:Field>
<igDp:Field Name="DecimalField" Label="DecimalField" Width="100*">
<igDp:Field.Settings>
<igDp:FieldSettings
EditAsType="{x:Type sys:Decimal}">
<igDp:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igEditors:XamMaskedEditor}">
<Setter Property="Mask" Value="99999.999" />
</Style>
</igDp:FieldSettings.EditorStyle>
</igDp:FieldSettings>
</igDp:Field.Settings>
</igDp:Field>
</igDp:FieldLayout.Fields>
</igDp:FieldLayout>
</igDp:XamDataGrid.FieldLayouts>
Your mask ("99999.999") is such that you are just specifying optional numeric digits but that doesn't mean as a whole it's a number so when you paste the editor just applies the characters in the text coming from the clipboard to the mask characters and since the ',' doesn't fit/match it's an error. It would be better if you used the n's to specify that it's a numeric section (of a specific size). e.g. "nnnnn.nnn". When you do that the paste works because it will ignore/skip digit grouping symbols like the ','. See the masks help for more on those characters.
Unrelated to this I would highly suggest you change your field to be the specific editor type so you can set properties on it without needing to use a style. In this way you also won't step on any styling that might be provided for that element if you were to set the Theme.
e.g.
<igWpf:MaskedTextField
Name="DecimalField"
Label="DecimalField"
Width="100*"
EditAsType="{x:Type sys:Decimal}"
Mask="nnnnn.nnn">
</igWpf:MaskedTextField>
Also you might get quicker support if you post on the Infragistics forums directly.
So I have a label which is bound to some text in my view model like so:
<Label VerticalOptions="Center" Text="{Binding Note, StringFormat='"{0}"'}" Style="{StaticResource ListItemSubTitleStyleDefault}" LineBreakMode="WordWrap" FontAttributes="Italic"/>
And I am trying to get the note to be surrounded in quotation marks like so
"I am a Note"
looking at some WPF answers it suggested using the following in the StringFormat property '"{0}"'
But this doesn't seem to work. Does anyone know how to surround a Labels text in quotation marks in Xamarin.Forms?
As you've seen, Xamarin.Forms is different from WPF for this case. For Xamarin, do this:
<Label VerticalOptions="Center" Text="{Binding Note, StringFormat='{}"{0}"'}" .../>
In order to prevent the runtime from ignoring the double quotes, the first double quote either has to be escaped (as above), or it can't immediately follow the single quote (see below).
So for example, throwing in a space in between works as well:
<Label VerticalOptions="Center" Text="{Binding Note, StringFormat=' "{0}"'}" .../>
With this latter solution, there will be at least one character rendered before the double quote.
On the code from your ViewModel you can also do this:
string _note;
public string Note => string.Format("\"{0}\"", _note);
I hope this helps.
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 have the following XAML. The idea is to append the text " For Report" after a string that is coming from a bound XML file.
<GroupBox Header="{Binding XMLData.Element[HeadingText].Value}"
HeaderStringFormat="For Report">
When I add {0} to the beginning of the HeadingStringFormat String like so, the application ignores the HeaderStringFormat and simply puts up the databound value.
<GroupBox Header="{Binding XMLData.Element[HeadingText].Value}"
HeaderStringFormat="{0} For Report">
However, when I add a single space (or any other character for that matter) after the quote, but prior to the left {, the application works fine.
<GroupBox Header="{Binding XMLData.Element[HeadingText].Value}"
HeaderStringFormat=" {0} For Report" >
In the first example, the editor seems to think that the string (between the quotes) isn't a string anymore, but if I put in that space, it's happy.
Try prefixing your format string with {}. This should work:
<GroupBox Header="{Binding XMLData.Element[HeadingText].Value}"
HeaderStringFormat="{}{0} For Report">
For further information, see MSDN: {} Escape Sequence / Markup Extension
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