Xamarin Binding Special Characters - xaml

I am pulling some data from a remote DB and inserting them into a ResourceDictionary. My app will take the a key and get a value based on the chosen language.
My XAML looks like this:
<Label Text="{Binding Dictionary[, Something:]}"/>
<Label Text="{Binding Dictionary[" Why" - where what!]}"/>
So, if a user chooses Danish, the Label will use the key ", Something" and translate it to the Danish word.
The problem I'm having seems to be that I can't use special characters like "," and ":".
I have tried replacing those with Unicode and ASCII characters but it didn't work.

Related

Xamarin Line Breaking does not seem to honor Horizontal Options or Row Height AUTO

I have the following Xaml inside a Grid:
<Label Grid.Row="4" Grid.Column="0" Text="Special characters" HorizontalOptions="End" VerticalOptions="CenterAndExpand" LineBreakMode="WordWrap"/>
The Row Height is AUTO. When the column is wide enough for the text all works as expected. But if the column becomes so narrow that the text does not fit on one line, Xamarin seems to honor neither the HorizontalOptions="End" nor the Row Height of AUTO. I get something like the following (I am using | to represent the width of the column) but with the bottom half of the word "characters" cut off.
|Special |
|Characters |
If I force the break with a hard line break ( & # 10 ;) then it solves the row height issue -- all of the word "characters" appears -- but the justification is better but still wrong:
| Special |
| Characters|
I have tried various combinations of End and EndAndExpand and Center and CenterAndExpand.
Anyone have a solution or a clue?
Thanks,
Use HorizontalTextAlignment=“End”

Show '...' when text is longer that the area in textblock

Some days back i saw an example of what i need now but couldn't remind what was the way.
I want to show the text description in TextBlock and if the text is more that the size of text block, show the ...
Use below code to achieve this,
<TextBlock Text="{StaticResource someText}"
TextWrapping="Wrap" TextTrimming="CharacterEllipsis"
Margin="10"/>
And possible values of TextTrimming are as below,
None – no ellipsis, text is clipped (the default)
CharacterEllipsis – display as many characters as possible, followed
by an ellipsis
WordEllipsis – display as many words as possible, followed by an
ellipsis
I know link only answer are frowned upon but
TextBlock.TextTrimming Property
<TextBlock
Name="myTextBlock"
Margin="20" Background="LightGoldenrodYellow"
TextTrimming="WordEllipsis" TextWrapping="NoWrap"
FontSize="14">
One<LineBreak/>
two two<LineBreak/>
Three Three Three<LineBreak/>
four four four four<LineBreak/>
Five Five Five Five Five<LineBreak/>
six six six six six six<LineBreak/>
Seven Seven Seven Seven Seven Seven Seven
</TextBlock>

How to use comma separator to display my double value as currency value in WinRT?

i want to use comma separator to display my double value as currency value in WinRT XAML?
like
<TextBlock Text="{Binding Amount, StringFormat={}{0:C}}" />
I need to achieve this in XAML, not in C# using IValueConverter.
Thanks in advance.
Joy Rex
Sounds like something that should be delegated to be handled by the platform, not by some arbitrary format string, doesn't it? I believe this should happen automatically for users using a locale that uses commas as separators such as Polish. I don't have much recent experience with that in .NET, but perhaps a decimal type would make it work if double doesn't. Also remember that you can simply expose an AmountAsString property that is formatted by your view model since you only bind it one-way into a TextBlock anyway. Oh and otherwise - there is nothing wrong with an IValueConverter.
Just to note on this thread, the Windows.Globalization.NumberFormatting APIs are available for both currency and decimal formatting, and automatically applies the user's locale-specific or customized number formats along with currency symbol placement. The Number formatting and parsing sample shows all the variations.

Multiple Colors In TextBlock

Is it possible to add dynamic colors to a TextBlock ..i.e. have one character in one color and the next in another color.
<TextBlock Text="{Binding no}" TextWrapping="Wrap" Margin="10,0,0,0" Style="{StaticResource PhoneTextSubtleStyle}" FontSize="40" Foreground="#A400C4FF" >
// Can we add something here to specify what colours for what chars
</TextBlock>
Basically I input a dynamic 4 character sequence from no. I've bound it to this TextBlock inside a ListBox. Is it possible to have the characters in different colors.
If so is it possible to add these colors dynamically for eg. If I click a button certain characters change color?
Thank You. Any Help is appreciated.
Actually, you can, which can come in handy when you're doing a StringFormat on a data bound Textblock or a number of other places.
If you did want to try it though, like here's an SL example for a form label that puts a red asterisk next to the text Required Fields, but then can also add more stuff to it as shown in the example. Should work for Silverlight, WPF, UWP, etc...
<TextBlock>
<Run Text="*" Foreground="#FFE10101"/><Run Text="Required Line" />
<Run Text="Red" Foreground="Red"/>
<Run Text="Blue" Foreground="Blue"/>
<Run Text="{Binding SomeString, StringFormat='Hell ya you can make \{0\} a different color!'}" Foreground="Orange"/>
</TextBlock>
I'm developing for Mango with the WP7 SDK. You can use a <Run>. It seems a little buggy on WP7 , you have to add a spaces on the Run.Text property to get the spacing correct:
<TextBlock>Hello<Run Foreground="Bisque" Text=" Holla "></Run>and hello again!</TextBlock>;
to set foreground color dynamically to a textblock
use: txtblockname.Foreground= new SolidColorBrush(Colors.Yellow);
The TextBlock does not support multiple Foreground colors.
You could recreate this behaviour by using multiple textblocks (one for each letter) and placing them within a wrappanel. You could then change the color of individual characters/letters as you wish.
Beware of the probable performance impact this may have. The margins around individual letters will need to be adjusted to recreate standard behaviour though. Be especially careful around punctuation.

How to include an ampersand (&) in the content of a ComboBoxItem

I currently have a Combobox like the following:
//XAML
<ComboBox>
<ComboBoxItem> Awake & Alive</ComboBoxItem>
</ComboBox>
This raises an error:
Entity references or sequences beginning with an ampersand '&' must be terminated with a semicolon ';'.
I assume I am missing an escape sequence of some sort to allow me to use a &. How can I set the content of this comboboxitem to include a &?
Use & to encode the ampersand.
//XAML
<ComboBox>
<ComboBoxItem> Awake & Alive</ComboBoxItem>
</ComboBox>
The short answer is to use & to encode an ampersand.
See also Entities: Handling Special Content on XML.com:
At the lowest levels an XML parser is just a program that reads through an XML document a character at a time and analyzes it in one way or another, then behaves accordingly. It knows that it's got to process some content differently than other content. What distinguishes these special cases is the presence of such characters as "&" and "<". They act as flags to the parser; they delimit the document's actual content, alerting the parser to the fact that it must do something at this point other than simply pass the adjacent content to some downstream application.
... So one way to get around your immediate problem is to replace the ampersand in your content with the appropriate entity reference: <company>Harris & George</company>.
Alternatively, you can use the CDATA tag around the contents of the ComboBoxItem element; I think it better maintains the text's readability.
//XAML
<ComboBox>
<ComboBoxItem><![CDATA[Awake & Alive]]></ComboBoxItem>
</ComboBox>
For reference: http://www.w3schools.com/xmL/xml_cdata.asp