where to put images for xamarin forms application - c#

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.

Related

How to set background image of ContentPage in Xamarin

I am trying to set a background image on my Xamarin app.
I saw already Xamarin Forms ContentPage background image tiling article.
At that code, has set a background image from the URL.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="SuperForms.Samples.Page1">
<ContentView>
<Image Source="https://i.stack.imgur.com/ajyCo.png"
Aspect="AspectFill"/>
</ContentView>
</ContentPage>
I want to set from local Resources. So I have modified the XAML file like the following code. But It doesn't work. How to should I fix the following code.
I want to set the background image via only the XAML file. not via C# code.
MainPage.xaml
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="SuperForms.Samples.Page1">
<ContentView>
<Image Source="Image/background.png"
Aspect="AspectFill"/>
</ContentView>
</ContentPage>
This is my Xamarin solution structure.
I want to build my app on Android, iOS, and Windows.
Please let me know in detail because I am a beginner at Xamarin.
Best regards.
According to xamarin document:
Image files can be added to each application project and referenced
from Xamarin.Forms shared code. This method of distributing images is
required when images are platform-specific, such as when using
different resolutions on different platforms, or slightly different
designs.
And on andriod.Place images in the Resources/drawable directory with Build Action: AndroidResource. High- and low-DPI versions of an image can also be supplied (in appropriately named Resources subdirectories such as drawable-ldpi, drawable-hdpi, and drawable-xhdpi).
see the link below:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=windows

print from resources (resw) directly in view on uwp | WPF

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

How can I display a font awesome glyph in XAML/C#

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\U‌​AP10\
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)

panorama controls windows phone 8.1

I 'm developping a windows phone 8.1 application and I would like to make a view with the panorama control but Its impossible to find the control
I have the Pivot control but not the panorama, is the panorama control is available on windows phone 8.1 ?
I have find nothing on it on the Internet so far :/
Thanks for the help :)
The Panorama control has been renamed Hub because it’s now available on both Windows Phone and on Windows. So, you would do something like:
<Hub Header="My header">
<HubSection Header="My sub header">
<DataTemplate>
<Grid />
</DataTemplate>
</HubSection>
<HubSection Header="My sub header 2">
<DataTemplate>
<Grid />
</DataTemplate>
</HubSection>
There are some changes in the API, as you will use HubSection instead of a PanoramaItem, and you must have a DataTemplate inside a HubSection, so be sure to check the following reference:
https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.hub.aspx
There are some nuances as a slightly different and odd behaviour when you have only 2 HubSections, as noted here: Windows Phone 8.1 app with 2 hub sections, but that may or may not be an issue for you. Some guidelines and implementation examples can be found here:
https://msdn.microsoft.com/en-us/library/windows/apps/dn449149.aspx

Add popup menu to AppBarButton

I want to add a contextual menu to a button from the appBar(bottom appBar). My min SDK is Windows 8.0. I would like something like this popup from MSDN:
Unfortunately I cannot use MenuFlyout since it is available only from Windows 8.1+, so I want to achieve this menu in another way. If you know how it can be done, please tell me.
Below is my bottom bar:
<common:LayoutAwarePage.BottomAppBar>
<AppBar x:Name="bottomAppBar" Padding="10,0,10,0" DataContext="{Binding}">
<Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Button Style="{StaticResource EditAppBarButtonStyle}" Click="EditQuote_Click"/>
<Button Style="{StaticResource RemoveAppBarButtonStyle}" Click="RemoveQuote_Click"/>
<Button Style="{StaticResource AddAppBarButtonStyle}" Click="AddQuote_Click"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Style="{StaticResource HelpAppBarButtonStyle}"/>
</StackPanel>
</Grid>
</AppBar>
You should take a look at the Flyout Settings sample at:
http://code.msdn.microsoft.com/windowsapps/Settings-Flyout-eceaafea
Or if you are targeting Windows 8.1, flyouts have become much easier, check the MenuFlyout element:
http://msdn.microsoft.com/en-us/library/windows/apps/bg182878.aspx#menuflyout
I would look at the Callisto library on Nuget. It's built by Tim Heuer who's one of the guys working on the xaml team at Microsoft and fills in some of the gaps in the 8.0 control set. It includes a Menu Flyout control that looks not that coincidentally like the controls added in 8.1.
The samples app in the project includes an example of what you're looking for (a Menu Flyout from an App Bar).
Edit: If you're targeting Windows 8.1 with your project then the Menu Flyout control is now built into the platform.

Categories