Xamarin forms-based application crashes in iOS 16 beta for Arabic languages when there are two lines in the resx string. Also, it will crash if we apply "\n" in the code when binding to XAML file.
example
<data name="some_key" xml:space="preserve">
<value>هذا الإصدار من نوع ألفا!
.استخدام هذا التطبيق مخصص لغرض الاختبار فقط</value>
</data>
Used resx in XAML file like below
<Label HorizontalTextAlignment="Start"
Text="{localization:Translate some_key}">
</Label>
Is this a problem with Xamarin forms or iOS?
The actual suggested workaround is: If we remove the ar from info.plist Localizations then it will not crash for new line
Related
I'm trying to use a resource file in my XAML. For some reason i keep getting the error of not finding the type Texts. Not sure what I'm doing wrong here.
XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:CashRegisterApp.Resources"
x:Class="CashRegisterApp.Start">
<ContentPage.Content>
<StackLayout
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" >
<Label Text="{x:Static local:Texts.Start}"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
RESX
Solution explorer
Creating RESX files within Shared projects is known to cause issues. You can see several lengthy posts in Xamarin Forums regarding this (here and here for example).
The easiest solution that will allow you to use the approach you want is to create a new .NET Standard Library of PCL library in your solution, create your RESX files there and set their visibility to public. Then you will be able to utilize them using the x:Static syntax as expected.
Many developers use an alternative in the form of a custom markup extension like the solution by ClaudioPereira in this forum. This simplifies the syntax even more.
Finally, for most detailed information on Xamarin.Forms you can refer to the official documentation.
I had this issue too and I hope this answer helps people in the future with this issue.
Following this guide taught me how to set up resx files in Xamarin forms.
Their TranslateExtension allows for referring to the resx file directly from Xaml.
Unfortunately, in its raw form it doesn't pick up a runtime change in locales.
This is fixable by changing their "Localize" class (on the native platforms) to keep a reference of the CultureInfo when changed via the SetLocale method and return it when the GetCurrentCultureInfo method is called.
Have an issue by using the Template10 for UWP apps. If i want to display special characters at design time everything seems to be ok. At runtime special characters would not be displayed correctly as you can see in screenshots.
<!-- page header -->
<controls:PageHeader Content="Übersicht">
<controls:PageHeader.SecondaryCommands>
<AppBarButton Click="{x:Bind ViewModel.GotoSettings}" Label="Settings" />
<AppBarButton Click="{x:Bind ViewModel.GotoPrivacy}" Label="Privacy" />
<AppBarButton Click="{x:Bind ViewModel.GotoAbout}" Label="About" />
</controls:PageHeader.SecondaryCommands>
</controls:PageHeader>
For example "Übersicht"
-> VisualStudio Designer "Übersicht"
-> Runtime "?bersicht"
Designer view
Runtime
If you use string resources (.resw files), the characters will also appear correctly:
XAML: x:Uid="..."
C#: ResourceLoader.GetForViewIndependentUse().GetString("...");
Did you set your PrimaryLanguageOverride?
You're dealing with UTF-8 by default, so I'd normally expect it to be fine but in this instance if you don't wish to set your localization you can substitute unicode Ü to reliably display Ü
Since Windows 10 has .NET introduced the property FontIcon.Glyph. If you add code below to your xaml page if gives me next char Σ.
<FontIcon FontFamily="Candara" Glyph="Σ"/>
So I was thinking can you add an other icon font like Font Awesome or Icomoon info your project?
I've download a font, added into my solution and I use this code:
<FontIcon FontFamily="ms-appx:/Fonts/FontAwesome.otf#FontAwesome" Glyph="" Foreground="Black"/>
what results into this:
How i can convert SVG file to XAML in windows 8 / WinRT. I am new to this XAML / SVG environment. So anyone please help me to implement the same in windows 8. I need to parse this svg file and need to display the content in the page through code.
For me the simplest way to do it is the following:
Open your .svg file in free vector drawing tool Inkscape
Save as "Microsoft XAML (*.xaml)"
Also you may need to update the result output file a bit after conversion, since not all XAML processing engines support converting a string to Figures (as described in the accepted answer to Why does this Xaml Path crash silverlight?). So, for example, if you have this:
<Path Fill="#FFEDEDED" StrokeThickness="1" Stroke="#FFA3A3A3" Opacity="0.7"
VerticalAlignment="Center" HorizontalAlignment="Center" >
<Path.Data>
<PathGeometry Figures="m 1 2 l 4.0525 5.2361 l 4.0527 -5.2361 z "/>
</Path.Data>
</Path>
then you will need to change it to this:
<Path Fill="#FFEDEDED" StrokeThickness="1" Stroke="#FFA3A3A3" Opacity="0.7"
VerticalAlignment="Center" HorizontalAlignment="Center"
Data="m 1 2 l 4.0525 5.2361 l 4.0527 -5.2361 z" />
- OR -
You could use a bit different way to export the xaml from Inkscape, described by Tim Heuer in accepted answer to the question Convert SVG to XAML, because both ways produce different xaml output:
Method (yes, superhack):
Use Inkscape to save as PDF
Rename the Filename extension from PDF to AI
Use Expression Design to open AI document
Export to Silverlight Canvas
UPDATE (2015-08-25)
I've found my self using the second ("hack") way more and more often rather then first (more straightforward) one, because it creates more "expectable" XAML as I would call it.
I cheated and converted my SVG to a font. First, I created the SVG, then using IcoMoon created the font. https://icomoon.io/app/#/select.
I downloaded the font's ttf into my assets folder with content.
Next I add the code. Notice the font filename, then #, then the name of the font. The text should be
<TextBlock Text="" FontFamily="/Assets/icomoon.ttf#icomoon" FontSize="45"</TextBlock>
Please take a look at this article:
Transforming SVG graphics to XAML Metro Icons
You can find here a way to convert via transforming to XPS.
You can use also an Svg2Xaml converter.
There is a free converter available in the Microsoft Store (as standalone Windows application). It is called SVG to UWP XAML Converter.
It worked without any problems converting my multi-color SVGs correctly as batch to XAML, which I added to Visual Studio within a WPF User Control (for a preview you need to select the SVG file manually)
I am currently making a basic Windows Phone 7 application for fun, and I am trying to store string (currently only those) values in a RESX file rather than embedding them all within the XAML files directly, or even adding code to manually insert the values.
In WPF, to use the property from the RESX file, you simply map the namespace that contains the RESX:
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:resx="clr-namespace:Namespace.To.Your.Resx;assembly=SuppliedIfSeparate"
and then use it:
<TextBlock Text="{x:Static resx:Strings.AppTitle}" />
But, I tried, and I've read that x:Static is simply not supported by Silverlight, and by extension, not supported in WP7 (It appears that they have provided the means, but not direct access to x:Static (French) in Silverlight 5/Mango).
I found this post describing an "AppConverter" class that is manually created to leverage similar functionality and it is currently what I am doing. The gist of the post is to create a resource within your XAML page that uses the AppConverter class for pre-specified keys, and then using that to replace the x:Static with a binding.
<TextBlock Text="{Binding Source={StaticResource AppTitle},Converter={StaticResource ResourceRetriever}}" />
It works, but it's verbose and error prone compared to the WPF implementation (a lot of copying and pasting between pages, and even controls).
What is the current best practice for this situation?
MSDN How to: Build a Localized Application for Windows Phone