Xamarin Forms - ResourceDictionary and <System:Uint32> value - xaml

It's a simple question, maybe stupid, but I'm stuck from hours..
I have that in the XAML part:
<ContentPage.Resources>
<ResourceDictionary>
<System:Uint32 x:Key="UintValue">50</System:Uint32>
</ResourceDictionary>
</ContentPage.Resources>
Of course, to have the <System> type access, I had this line:
xmlns:System="clr-namespace:System;assembly=mscorlib"
However, I have an XAML parse Exception.. When I comment <System:Uint32...</System:Uint32> then it works. #ButIDontHaveTheValue..
There is a link to the doc of Uint
Type | Range | Size | .NET Framework type
uint | 0 to 4,294,967,295 | Unsigned 32-bit integer | System.UInt32
So If I'm right, then Uint32 is coming from System, so I have to reference it like System:Uint32 isn't?
Thank for help !

Its a bit late but I will post an answer anyway. The type you need to import should be UInt32 instead of Uint32, case sensitive. Anyway if you want to bind this value to a Margin or similar value you should use String instead because they could take more integers separated by a colon and they are a String.
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib">
...
<System:UInt32 x:Key="sdsd">15</System:UInt32>
...
</ContentPage>

Related

Xamarin.Forms - Is there a quick and easy way to increment the already bound value of Label.Text in XAML only?

I need to increment the value of some labels without changing the value of the binding context.
I know I could just create a new variable in my MVVM which is the incremented version of my original value but is there an easy and fast way to do the same thing in XAML only (since I would need to change this projectwide and only need this for frontend)?
Does something like this exist?
<Label>
<Label.Text>
<MultiBinding StringFormat="INCREMENT BINDING BY 1">
<Binding Path="MyValue">
</MultiBinding>
</Label.Text>
</Label>
^Pseudo code which I have in my mind
The easiest way to increment the property myValue in label.text is to create a new property in MVVM
myValuePlus1{ get { return myValue + 1; }} and use myValuePlus1 as binding source instead of myValue.

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”

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.

Writing XML Exactly as XML Literals are Written

I'm transforming some XML from DrawingML to XAML. Unfortunately, the XAML one is not working as expected with white spaces, but I have found a work around. Here's the problem:
Problem Statment
I want to write the following in a TextBlock:
Hi John, what did Sushi A say to
Sushi B?
So I would write:
<TextBlock>
<Run>Hey</Run>
<Run FontWeight="Bold">John</Run>
<Run>,</Run>
<Run FontStyle="Italic">what did Sushi A say to Sushi B?</Run>
</TextBlock>
This doesn't produce the desired results. Instead, it produces:
Hi John , what did Sushi A say to
Sushi B?
Notice the space now between "John" and ","? Weird, eh? This is because XAML appends a space between runs. I don't know why it does this. I really do need the formatting exactly as above, so the option of changing formatting, like making the comma bold too is not an option.
Partial Solution
The weirder thing is that there is a way around this - i.e. to lose the extra space that XAML adds - you have to put your runs on the same line. I have no idea why, but that's the case. So the following actually works just fine:
<TextBlock>
<Run>Hey</Run>
<Run FontWeight="Bold">John</Run><Run>,</Run>
<Run FontStyle="Italic">what did Sushi A say to Sushi B?</Run>
</TextBlock>
Notice runs #2 and #3 (of 4 runs) are now on the same line.
Question
The issue I'm having is that I haven't found a way to write the above using XML Literals. If I try this:
Dim tb = <TextBlock>
<Run>Hey</Run>
<Run FontWeight="Bold">John</Run><Run>,</Run>
<Run FontStyle="Italic">what did Sushi A say to Sushi B?</Run>
</TextBlock>
it is always created as the below, with the 4 runs on seperate lines:
<TextBlock>
<Run>Hey</Run>
<Run FontWeight="Bold">John</Run>
<Run>,</Run>
<Run FontStyle="Italic">what did Sushi A say to Sushi B?</Run>
</TextBlock>
Does anyone know how XML can be written exactly as written in XML Literals?
Bonus
If you answer the question correctly, I'll tell you the punchline of the joke :)
I don't suppose using a span will help you (as it will keep non-formatted text out of XML elements so it might not get auto-formatted).
i.e.
<TextBlock>
<Span>
Hey
<Bold>John</Bold>,
<Italic>what did Sushi A say to Sushi B?</Italic>
</Span>
</TextBlock>
Obviously this only fixes the specific case not the general, I would probably suggest not using XML literals :)
Any chance the unicode backspace character would solve your problem?
http://www.fileformat.info/info/unicode/char/0008/index.htm
Update
One other idea. Have you looked into the XDocument.Save(TextWriter textWriter, SaveOptions saveOptions) method? The documentation says that if you use SaveOptions.DisableFormatting, it will preserve spacing.