I have the following xaml which includes the font family serif
It shows as sans serif
<Label Text="{Binding Name}" FontFamily="serif" Style="{StaticResource largeLabel}" HorizontalOptions="FillAndExpand" />
In fact whatever I put on it doesn't seem to have any effect I have tried custom fonts, font names like arial, font families like serif and it never changes.
I have tried in android and uwp on pc
Thanks for your help
In fact whatever I put on it doesn't seem to have any effect I have tried custom fonts, font names like arial, font families like serif and it never changes.
Like Jason said.Using a font other than the built-in typefaces requires some platform-specific coding.
<Label Text="Hello Forms with XAML">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<On Platform="iOS" Value="Lobster-Regular" />
<On Platform="Android" Value="Lobster-Regular.ttf#Lobster-Regular" />
<On Platform="UWP" Value="Assets/Fonts/Lobster-Regular.ttf#Lobster" />
</OnPlatform>
</Label.FontFamily>
</Label>
iOS
Add the font file with Build Action: BundleResource,
Update the Info.plist file (Fonts provided by application, or
UIAppFonts, key), then
Refer to it by name wherever you define a font in Xamarin.Forms!
Android
Add the font file to the Assets folder in the application
project and set Build Action: AndroidAsset.
Use the full path and Font Name separated by a hash (#) as the
font name in Xamarin.Forms
UWP
Add the font file to the /Assets/Fonts/ folder in the
application project and set the Build Action:Content.
Use the full path and font filename, followed by a hash (#) and
the Font Name
Here is the official document.Use a custom font
I deleted each attributte one by one until only the next was left and it started working:
<Label Text="Test" FontFamily="serif" />
The I re-added each attributte one by one and it still worked, I changed a few other things and it still worked.
I have no idea what was the problem
Related
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:
I'm developing a cross pltform app with Xamarin.Forms. I want to make a button with an image but I dont know how to specify the path of the imge. When I use this annotation it works:
<Button Text="Naviga tra i Piani del Museo" Image="foo.png"/>
but when my image is inside some folders (folder1/folder2) the following code doesn't work:
<Button Text="Naviga tra i Piani del Museo" Image="folder1/folder2/foo.png"/>
So how can I correctly specify the path of my image?
You can't nest the images in folders. iOS and Android expect them to be resources, and WP expects them to be in the App's root folder.
The Xamarin Forms docs has a section on working with images.
Keeping the image common using PCL is a difficult task.
So do it separately.
Keep in mind that you have to copy the images to Resources>drawable in case of android project.
For using folders for Xamarin.Forms project this is what worked for me.
You need to put your resources (image file in this case), to folder inside Xamarin.Form project (for this example folder is called "Assets") and set Build Action "Content".
Secondly for resources to work with Android you need to put files to Resources>drawable folder inside Android project (here you cannot use any folders), Set Build Action "AndroidResource".
<ContentPage.Resources>
<ResourceDictionary>
<OnPlatform x:Key="StartButtonImage"
x:TypeArguments="FileImageSource"
Android="button_image.png"
WinPhone="Assets\button_image.png"
iOS="Assets/button_image.png"/>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<Grid>
<Button Image="{StaticResource StartButtonImage}" BackgroundColor="Transparent"/>
</Grid>
</ContentPage.Content>
Pay attention that for iOs you need to make path using "/" and for WinPhone/UWP using "\".
You should specify Image property of button in OnPlatform tag to give different path for each platform. This is the example of Box View, you can try the same for Button Image property.
<BoxView HorizontalOptions="Center">
<BoxView.Color>
<OnPlatform x:TypeArguments="Color"
iOS="Green"
Android="#738182"
WinPhone="Accent" />
</BoxView.Color>
<BoxView.WidthRequest>
<OnPlatform x:TypeArguments="x:Double"
iOS="30"
Android="40"
WinPhone="50" />
</BoxView.WidthRequest>
</BoxView>
i tried to load a downloaded font in windows phone app.
i installed the font in pc.
i tried following
<TextBlock Width="237" Text="About" FontSize="36" Height="46" LineHeight="8"
FontFamily="{StaticResource nokia}"/>
<TextBlock Width="237" Text="About"
FontFamily="/font/nokia.ttf#Nokia Cellphone" FontSize="36" Height="46" LineHeight="8"/>
why external font is not loading
It doesn't matter if the font is installed on the PC or not.
For a font to work inside your app you'll need a few things.
You'll have to set the build action to 'Content' and output to directory set to: 'Copy if newer'.
And then the hardest part - Getting the preferred family right. I usually advocate using a tool for it, because the Windows Font viewer does not always show the right one.
'dp font viewer' is the one I usually use.
For a complete guide on implementing custom fonts, you could have a look here: http://www.blendrocks.com/code-blend/2015/01/04/a-complete-guide-to-working-with-custom-fonts-in-your-windows-and-windows-phone-app
I have an own font as files in the project and do an overwrite of the default fontfamily key in the globalstyle.xaml (like described in the post Change global application font in a Windows 8.1 app):
<FontFamily x:Key="ContentControlThemeFontFamily">/Assets/Fonts/myFontType-Roman.ttf#myFont Type</FontFamily>
This works like a charm - for one font file.
My question:
Is it possible to have a font Family Group references in the style instead of just one file somehow?
The only possiblity I found is for WPF and seems not to work in WinRT (Add font family in resourceDictionary)
I have four font files (myFontType-Bold.ttf, myFontType-Light.ttf, myFontType-Italic.ttf and myFontType-Roman.ttf), which are one font Family group, when locally installed on the System. But the font should not be installed on the System.
One idea was to define four keys and add all four fontfamilies. But this is not an Option, since we want to use the different font weight through the keyword fontweight in the style and not by reference different font families.
Any ideas or correct ways to Group These files into one Group and overwrite the "ContentControlThemeFontFamily" key to apply the fontFamily to the whole app.
Thank you for any ideas.
Edit:
By the way, I tried also to only use the font Family Name:
<FontFamily x:Key="ContentControlThemeFontFamily">/Assets/Fonts/#myFont Type</FontFamily>
But this seems to have no effect...
You can change font family by simply using attribute i.e (FontFamily).
Code must look like this :-
<TextBlock Content="Meal-" Foreground="Black" FontFamily="Assets/Font/MixBrush.ttf#MixBrush" FontWeight="Bold" FontSize="55" />
Here Assets/Font/MixBrush.ttf#MixBrush is located in manifest file.
Thanks & Regards,
I have a reasonably large Silveright 3.0 project on the go, and I'm having issues accessing a couple of custom font resources from within one of the assemblies.
I've got a working test solution where I have added a custom font as a resource, and can access it fine from XAML using:
<TextBlock Text="Test" FontFamily="FontName.ttf#Font Name" />
The test solution consists of the TestProject.Application and the TestProject.Application.Web projects, with all the fun and games obviously in the TestProject.Application project
However, when I try this in my main solution, the fonts refuse to show in the correct type face (instead showing in the default font). There's no difference in the way the font has been added to project between the test solution and the main solution, and the XAML is identical.
However, there is a solution layout difference. In the main solution, as well as having a MainApp.Application and MainApp.Application.Web project, I also have a MainApp.Application.ViewModel project and a MainApp.Application.Views project, and the problem piece of XAML is the in the MainApp.Application.Views project (not the .Application project like the test solution).
I've tried putting the font into either the .Application or .Application.Views project, tried changing the Build Action to Content, Embedded Resource etc, all to no avail.
So, is there an issue accessing font resources from a child assembly that I don't know about, or has anyone successfully done this?
My long term need will be to have the valid custom fonts being stored as resources in a separate .Application.FontLibrary assembly that will be on-demand downloaded and cached, and the XAML controls in the .Application.Views project will need to reference this FontLibrary assembly to get the valid fonts. I've also tried xcreating this separate font library assembly, and I can't seem to get the fonts from the second assembly.
As some additional information, I've also tried the following font referencing approaches:
<TextBlock Text="Test" FontFamily="/FontName.ttf#Font Name" />
<TextBlock Text="Test" FontFamily="pack:application,,,/FontName.ttf#Font Name" />
<TextBlock Text="Test" FontFamily="pack:application,,,/MainApp.Application.Views;/FontName.ttf#Font Name" />
<TextBlock Text="Test" FontFamily="pack:application,,,/MainApp.Application.Views;component/FontName.ttf#Font Name" />
And a few similar variants with different assembly references/sub directories/random semi colons.
And so far nothing works... anyone struck this (and preferably solved it)?
This code works for me:
... FontFamily="/(DLL);Component/(DIR-optional)/(Font_file)#(Font_name)"/> ...