I have been following the Xamarin guide to adding fonts to my app. I have not had any issues with iOS or Android, but my UWP app is ignoring the font and using the default font.
I added my font to my UWP project in Assets\Fonts\FiraSans-Regular.otf.
My XAML markup to apply the font is as follows:
<Label HeightRequest="50" Text="My sample text">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.iOS>FiraSans-Regular</OnPlatform.iOS>
<OnPlatform.Android>FiraSans-Regular.otf#FiraSans-Regular</OnPlatform.Android>
<OnPlatform.WinPhone>Assets/Fonts/FiraSans-Regular.otf#FiraSans</OnPlatform.WinPhone>
</OnPlatform>
</Label.FontFamily>
</Label>
Does this appear to be the correct way to apply a font for my UWP app?
I've downloaded the Font and you did almost correct. Add the space in font name:
<OnPlatform.WinPhone>Assets/Fonts/FiraSans-Regular.otf#Fira Sans</OnPlatform.WinPhone>
You have to use correct font name which you can find during font installation.
Related
I am working on a Mobile App( Xamarin.Foirm). I have an WPF control that does animation that works, but now I am trying to convert it over to Mobile App( Xamarin.Frm) , so I can make a IOS, Android and UWP app that all uses the same base library.
However, the base library does not have a canvas nor a , So how do I add my svg to it as a path ?
<Viewbox>
<Path Name="path8" Canvas.Left="83.948" Canvas.Top="89.126" Width="971.099" Height="1047.555" Stretch="Fill" Fill="#FFE6F0FF" Data="M259.29 280.09c40.26-150 198.93-228.93 368.37-172.9c142.66 47.17 403.77 395 426 609.68 c21.09 203.81-200.17 404.81-536.78 418.9c-393.71 16.48-484.38-194.38-408.35-326.2C296 484.51 210.71 461 259.29 280.09z" d:IsLocked="True"/>
<Canvas/>
</Viewbox>
</ContentView.Content>
In visual Studios 2019 when you make an Mobile app (Xamarin.Forms) project you get 4 different projects. The 1st project is your base project( I do not know the real name for it) well it does not have a Canvas.
It does not have a path, viewbox nor canvas.
So how do I add my svgs and animation them, like I did with my WPF control?
Following this tips, (Xamarin.Forms: how to set background image of NavigationPage bar)
I change the Navbar bg image.
I can change this image in specific pages? Already exist some custom render for that?
Use various navbar's backgrounds...
I think you might succeed doing what you want with the new TitleView introduced in Xamarin Forms 3.2 for NavigationPage without any CustomRenderer or platformspecific code.
<NavigationPage.TitleView>
<Image Source="main_background_image.png" Aspect="AspectFill">
</Image>
</NavigationPage.TitleView>
https://learn.microsoft.com/fr-fr/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical#displaying-views-in-the-navigation-bar
The searchbar in forms doesn't appear on Android 7.0 devices, I am compiling with Android 6.0 not the latest version. The issue is apparently a google problem with calculating a height of the searchbar that results in a height of zero, thus no searchbar. I want to implement a searchbar size in XAML and only affect Android. Apparently, if I don't set the HeightRequest, Forms will use a default value or zero, so now the problem propagates to the other platforms. I read somewhere that if I set the HeightRequest to -1, it is invalid and Xamarin will calculate/default a height that makes sense and I can simply override the height for Android. I currently have this code in my XAML and it appears to work. I don't want to make a custom renderer, especially since the problem is apparently fixed in Android 7.1.
Anyone have a better solution?
Thanks
Alan
<SearchBar Text="{Binding Search}" Placeholder="Search order list" SearchCommand="{Binding SearchCommand}" >
<SearchBar.HeightRequest>
<OnPlatform x:TypeArguments="x:Double"
iOS="-1.0"
Android="40.0"
WinPhone="-1">
</OnPlatform>
</SearchBar.HeightRequest>
</SearchBar>
I'm trying to use the LayoutTransform property to rotate some text 90 degrees in a windows 8.1/VS2013 template.
I am aware LayoutTransform is not in WinRT XAML so I followed the instructions on igrali's blog for using Layout transform in Windows 8 WinRT XAML but visual studio keeps saying:
'The name Layout Transformer" does not exist in the namespace
"using:Transforming.Common.'
Is this because I need to do something differently due to the changes in windows 8.1?
Joe
Thanks everyone for the suggestions. I found out how to do it eventually. I just had to make sure I had the correct name spaces above the style in app.xaml and mainpage.xaml. I just copied the namespace for common already included in the template into app.xaml.
maybe you can try this:
<TextBlock Text="Sample Text">
<TextBlock.RenderTransform>
<RotateTransform Angle="90"/>
</TextBlock.RenderTransform>
</TextBlock>
I downloaded a custom font which displays EAN 128 barcode.
I also downloaded some source code and sample program which converts a string to an encoded string to use with the font (includes check sum etc).
I installed the font, opened my WPF app and set a textblock font to this new font and added some text. The text comes out as if it was Arial or something.
I tried adding the font as a resource and referencing it that way but still not joy.
So I then ran the program that came with the font. The interesting part I found was that when you entered text, the program encoded it and set a label's text and the barcode showed. However, that app allowed you to print preview and print the bar code but when you did the font of the barcode in the print preview and printout changed to like Arial or what ever it was, same issue as I am seeing in my app.
This is how the xaml looks at the moment but as I say, I have tried just setting the font in expression blend.
#Code 128 is the font name and not the file name.
<TextBlock x:Name="tbkBarCode" FontFamily="/Fonts/#Code 128" FontSize="24" HorizontalAlignment="Center"/>
Any ideas?
Try this:
<TextBlock x:Name="tbkBarCode" FontFamily="pack://application:,,,/Fonts/#Code 128" FontSize="24" HorizontalAlignment="Center"/>
EDIT: I tried a different font first and this way of doing it worked.
I downloaded and tried it with a Code 128 font and it didn't work right away. To get it to work I had to change the Build Action to "Content" and the Copy to Output Directory to "Copy if newer".
Here is the method I used to do that...
I add the Font on my project
I Set property "Build action" of the Font on "Resource"
Finally, I used the Font like that :
TextBlock Grid.Column="2" HorizontalAlignment="Center" FontSize="32" VerticalAlignment="Stretch" FontFamily="./#Code 128" Grid.Row="5" Margin="1" Text="{Binding Checksum}"/
If you create a test Windows Forms app, add a TextBox and select the "Code 128" font as the font to use, then it correctly shows the Barcode font.
With WPF it looks the rendering system inside that that deals with fonts doesn't like that particular font for some reason...maybe some information it expects in the file isn't there.
Even "Glyphs" has trouble getting anything sensible out of that font file:
<Glyphs UnicodeString="ABCD1234567890" FontUri="c:\windows\fonts\code128.ttf" Height="50" Fill="#FF000000" FontRenderingEmSize="25"/>
it just returns "blocks".....which means no-character.
When you use a TextBox/TextBlock etc....the fallback font is used to display the content (because it is unable to display it with the Code123 font)......which is why you see the text reverting to the Arial font (or whatever your fallback font is defined to be).
From where did you download the custom font and sample program...was it this place?
http://www.barcoderesource.com/wpfbarcode.shtml
Or from here?:
http://grandzebu.net/informatique/codbar-en/code128.htm
Are you sure the font name is #Code 128 ?
If you copy the .ttf font into your \Windows\Fonts directory and then use CharacterMap, what font names can you see?
After installation with the barcoderesource font, I have these fonts listed:
That would mean using:
FontFamily="CCode128_S3_Trial"
to refer to the font IF it was installed in Windows
or
FontFamily="/Fonts/#CCode128_S3_Trial"
to refer to a .ttf font file embedded into your application.
Did you add the .TTF font file to your project in a folder called "Fonts" and set the Build Type="Resource"?
http://msdn.microsoft.com/en-us/library/ms753303.aspx