I have tried many things in Visual Studio, but I still can not display a glyph.
Do I need to add a NuGet package? Which?
Do I need a 'using ...;' in C#?
Do I need a 'xmlns:...' in XAML?
Should I display it with a "Label"?
I know in HTML, you just add a class to your element. But I am stumped in XAML.
(It's cross-platform, right?)
This should a simple thing but I can not get any answers to function. Please provide an answer if you can do this and answer all points.
There is a correct plugin for Xamarin.Forms. This plugin not only has FontAwesome Font.
According to this example in github you must do the following:
<StackLayout Orientation="Horizontal">
<iconize:IconLabel FontSize="20" Text="{Binding Key}" TextColor="Green" VerticalTextAlignment="Center" />
</StackLayout>
[UPDATE]
On request from user3247130 I leave the complete example:
From Visual Studio or Xamarin Studio, install the following packages:
Xam.Plugin.Iconize
Xam.Plugin.Iconize.FontSwesome
Xam.FormsPlugin.Iconize
In the Android project, MainActivity class, OnCreate() method add:
FormsPlugin.Iconize.Droid.IconControls.Init(Resource.Id.toolbar);
Plugin.Iconize.Iconize.With(new Plugin.Iconize.Fonts.FontAwesomeModule());
In the iOS project, AppDelegate class, FinishedLaunching() method, add similar lines:
FormsPlugin.Iconize.iOS.IconControls.Init();
Plugin.Iconize.Iconize.With(new Plugin.Iconize.Fonts.FontAwesomeModule());
Also, in iOS project, info.plist add
<key>UIAppFonts</key>
<array>
<string>iconize-fontawesome.ttf</string>
</array>
Now, in your XAML where your have your toolbar, in tag, add
<ContentPage ...
xmlns:iconize="clr-namespace:FormsPlugin.Iconize;assembly=FormsPlugin.Iconize">
and
<iconize:IconLabel Text="fa-search" />
[UPDATE 2]
This plugin has an issue on UWP platform.
To run this plugin on UWP platform follow these steps:
First, create a folder called Plugin.Iconize.FontAwesome.UWP into %userprofile%\.nuget\packages\xam.plugin.iconize.fontawesome\2.0.0.29-beta\lib\UAP10\
Second, create another folder called Assets into Plugin.Iconize.FontAwesome.UWP folder
Third create anoother folder called Fonts into Assets folder
And finally copy iconize-fontawesome.ttf file (you shouldn't change their name).
Additionally, you have to add a Fonts folder in the Assets folder in your UWP project and then paste the same ttf file
This is not necessary on Android or iOS it is only a issue of the UWP platform
Try Plugin.Glypher it has Font Awesome 5 Free/Pro and WeatherIcons support.
Plugin.Glypher.FontAwesome5Free
Plugin.Glypher.FontAwesome5Pro
Plugin.Glypher.WeatherIcons
xmlns:fontAwesome5Free="clr-namespace:Plugin.Glypher.FontAwesome5Free;assembly=Plugin.Glypher.FontAwesome5Free"
xmlns:glypher="clr-namespace:Plugin.Glypher;assembly=Plugin.Glypher"
<Label glypher:FontGlyph.Glyph="{x:Static fontAwesome5Free:GlyphList.Fab_Bluetooth}"
FontSize="Large"
TextColor="CornflowerBlue" />
<Button glypher:FontGlyph.Glyph="{x:Static fontAwesome5Free:GlyphList.Fab_Bitcoin}"
FontSize="Large"
TextColor="IndianRed" />
<Image>
<Image.Source>
<FontImageSource Size="32"
Color="Orange"
glypher:FontGlyph.Glyph="{x:Static fontAwesome5Free:GlyphList.Far_Bell_Slash}" />
</Image.Source>
</Image>
It's all in shared code. But it depends on Xamarin.Forms (>= 3.6.0.344457)
Related
I am looking for a solution that lets the user pick the folder location where they want to save their file(s). I am aware of FilePicker in the Xamarin.Essentials package, but this only allows the user to pick individual files, not folders. I am trying to accomplish this for all 4 platforms (Windows, iOS, Mac, and UWP). Any help is greatly appreciated.
You can only achieve with Xamarin what is natively possible. If you try to code using native iOS in Objective-C/Swift/SwiftUI, there's no way to select which folder in the photo gallery to save your pictures in.
Therefore it's not technically possible to achieve a solution that you are looking for in all 4 platforms.
For now, no FodlerPicker in Xamarin.Forms.
You could create your own custom folder picker like below. Use the TapGestureRecognizer to simulate the selecting operation to save to the specific location.
<ListView ItemsSource="{Binding folders}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding folder}">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"></TapGestureRecognizer>
</Label.GestureRecognizers>
</Label>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
You could post your requirement in GitHub. https://github.com/xamarin/Xamarin.Forms/issues
Hi guys i'm building a Universal Windows App for windows 10 IOT.
So, I'didn't found a method to get a label value from resources file, directly from WPF.
There is a method like this:
<Button Content="{x:StaticResources local:mylabel" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Name="btnUpdate" Margin="0,200,0,0" MinWidth="300" Command="{Binding add}" />
on the "normal" WPF it's easy, but on universal windows app I didn't
found a solution.
The resources file within on Resources folder in my solution, while the page it's in view folder.
Thanks
In UWP you can use x:Uid directive to associate a control with a string resource identifier:
<Button x:Uid="mylabel" Name="btnUpdate" .... Command="{Binding add}" />
Please refer to MSDN for more information: https://learn.microsoft.com/en-us/windows/uwp/app-resources/localize-strings-ui-manifest
I am developing an application for Android, iOS and Visual Studio using Xamarin
I added the following lines in xaml to use images:
<Image Source="header.png" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" />
<Button x:Name="Object_Detection" Image="header.png" />
The first is for displaying an image in the header and the second is for displaying a button icon. They link for the same image "header.png"
I put the image under:
- Mobile.Droid\Resources\drawable
- Mobile.iOS\Resources
-Mobile.Windows\Assets
But the image is not shown at all in the Windows 8.1 app.
the image size is 690*79.
how to resolve the problem?
You have to place images in the root Project directory for Windows Phone 8, Windows Phone 8.1 and UWP applications.
This guide will help you
http://developer.xamarin.com/guides/xamarin-forms/working-with/images
Try something like this :
<ContentPage.Resources>
<ResourceDictionary>
<OnPlatform x:Key="ImageHeaders"
x:TypeArguments="ImageSource"
iOS="header.png"
Android="header.png"
WinPhone="Assets/header.png" />
</ResourceDictionary>
</ContentPage.Resources>
<Image Source="{StaticResource ImageHeaders}" />
OR
<Image.Source>
<OnPlatform x:TypeArguments="ImageSource">
<OnPlatform.iOS><FileImageSource File="header.png"/></OnPlatform.iOS>
<OnPlatform.Android><FileImageSource File="header.png"/></OnPlatform.Android>
<OnPlatform.WinPhone><FileImageSource File="Assets/header.png"/></OnPlatform.WinPhone>
</OnPlatform>
</Image.Source>
Not tested, but it seems to work well.
Thanks for all your posts,
the solution was to add the image resource to the windows sub-project directly under the root.
The addition should be made using visual studio so that the image will be taken in consideration by the compiler.
I tried to add google font to my silverlight project. so i downloaded the zip and added the fonts to Fonts folder:
I tried to load it like this:
<controls:DynamicTextBlock Grid.Column="2"
Width="200"
HorizontalAlignment="Left"
FontSize="{StaticResource FontSize6}"
FontFamily="/EZTrader;Component/Fonts/#RobotoLight"
Foreground="White"
Text="{Binding UserFullName}"
ToolTipService.ToolTip="{Binding UserFullName}" />
and nothing happened.
what should i do to fix this?
thanks!
If you are using windows, Open the font you want to use with Windows Font Viewer
Check the Font name:. That name is what you will use when referencing it. Note: the font name may not always match the filename of the .ttf and can also include spaces.
You want to make sure that the `Build Action' of the included file in the project is set to Resource as you want to be able to reference it from xaml.
You can create a static resource for the FontFamily in your App.xaml so you can reference it throughout your project.
Assuming the name of the assembly for your project is EzTrader.dll
<FontFamily x:Key="RobotoLightFontFamily">/EzTrader;component/Fonts/RobotoLight.ttf#[Font name here]</FontFamily>
<FontFamily x:Key="RobotoThinFontFamily">/EzTrader;component/Fonts/Roboto-Thin.ttf#[Font name here]</FontFamily>
<!-- other font resources -->
Then build the project.
From there you should be able to reference it like so
<controls:DynamicTextBlock Grid.Column="2"
Width="200"
HorizontalAlignment="Left"
FontSize="{StaticResource FontSize6}"
FontFamily="{StaticResource RobotoLightFontFamily}"
Foreground="White"
Text="{Binding UserFullName}"
ToolTipService.ToolTip="{Binding UserFullName}" />
Reference:
How to use your own fonts within Silverlight
Using Custom Fonts in Silverlight
Using built-in, embedded and streamed fonts in Silverlight
If you can, check what the display name of the font is, instead of the file name for the part after the #. It may actually be Roboto Light.
<controls:DynamicTextBlock FontFamily="/EZTrader;component/Fonts/RobotoLight.ttf#Roboto Light" />
You may also need to change the build properties on your font file as seen here: http://geekswithblogs.net/mamta_m/archive/2010/07/01/adding-custom-fonts-to-your-silverlight-application.aspx.
I have a class library that is essentially a collection of forms to be run. Consider it a module/plugin in a larger program, that can be developed independently, all the larger program cares about is the DLL (and interface).
Running the main form of the class library is fine and works well. My issue is with pictures. I've set up an Images folder in the class library, added an image, set it's Build Action to Embedded Resource and then rebuilt the project, but the images won't appear in the main program.
XAML:
<Button x:Name="btnAdd" Command="{Binding Add}">
<StackPanel Orientation="Horizontal">
<Image x:Name="imgAdd" Source="Resources/Add.png"/>
<Label>New</Label>
</StackPanel>
</Button>
The interesting part though, is that if I create a BitmapSource in code-behind and assign it to imgAdd in the constructor of the form, it works as expected. Does anyone have any ideas as to why this might be the case?
Use Pack URIs for your images.
<Button x:Name="btnAdd" Command="{Binding Add}">
<StackPanel Orientation="Horizontal">
<Image x:Name="imgAdd" Source="pack://application:,,,/ReferencedAssembly;component/Resources/Add.png"/>
<Label>New</Label>
</StackPanel>
</Button>
It turns out that the correct Build Action is actually Resource rather than Embedded Resource. Thinking about it now, Embedded Resource does seem more like a reference to a Resource in another DLL.
I inadvertently found the answer in this post while trying to improve my code.