Xamarin essentials FodlerPicker? - c#

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

Related

How can I use the “Xamarin.Forms.Contacts 1.0.3” Plugin to create a list view of the contacts?

I have been researching a plugin that allows me to access the contacts in the phone of the user to display them in a list view. I tried to use James Montemagno “ContactsPlugin” but it is no longer supported. So, I found a plugin called “Xamarin.Forms.Contacts 1.0.3” which claims to be able to access the contacts but I don't know how to activate the plugin for it to display the contacts. Does anyone know how to use this plugin or knows how to access the contacts using something else? I am currently using the latest version of Visual Studio 2017 for Mac.
Plugin link: https://www.nuget.org/packages/Xamarin.Forms.Contacts/
there is a sample app in the GitHub repo that demonstrates exactly what you want
var contacts = await Plugin.ContactService.CrossContactService.Current.GetContactListAsync();
lstContacts.ItemsSource = contacts;
<ListView
x:Name="lstContacts"
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="{Binding Name}"/>
<Label Text="{Binding Email}"/>
<Label Text="{Binding Number}"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

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)

EmbeddedImage in Xamarin Forms: how to bind it in XAML

I am trying to follow the Xamarin documentation about Embedded Images:
https://developer.xamarin.com/guides/xamarin-forms/working-with/images/#Embedded_Images
This is the code snippet that I use in my portable application:
var embeddedImage = new Image { Aspect = Aspect.AspectFit };
embeddedImage.Source = ImageSource.FromResource("<MyNamespace>.<MyFolder>.imageFileName.jpg");
listItem.EmbeddedImage = embeddedImage;
Now I am trying to bind it in XAML, as part of a ListView (note: the <Image Source="{Binding EmbeddedImage}" /> part is probably wrong) :
<ListView x:Name="listView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout BackgroundColor="#eee"
Orientation="Vertical">
<StackLayout Orientation="Horizontal">
<Image Source="{Binding EmbeddedImage}" /> // This is most likely wrong since it doesn't work
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I've tested this with <Image Source="{Binding ImageUrl}" /> and it works, so the rest of the code seems to be working as it should.
Edit:
Someone suggested this post as a solution:
How to load an image to a ImageCell on Xamarin.Forms?
But the accepted answer there was:
The images go into your "native" projects
...but actually the Xamarin documentation says that it can be done inside the portable project (so you wouldn't need to copy the same images/icons through all the "native" projects).
I know that putting them in every subproject would probably work, but that's not the point of my question.
You can access the resource directly in xaml by using pack://application uri.
<ListView x:Name="listView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout BackgroundColor="#eee"
Orientation="Vertical">
<StackLayout Orientation="Horizontal">
<Image Source="pack://application:,,,/{AssemblyName};component/Images/MyImage.png" />
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I've combed my hair out over this, and the problem is that Microsoft doesn't tell you the whole story in the Images docs. You have to go over to the Files docs to understand why it won't work.
Yes, you can use embedded resources in the shared project directory, but apparently under only one of two conditions:
You have to use a Markup Extension and then directly specify the resource path in Xaml, a la: <Image Source="{local:ImageResource ProjectName.Images.flower.jpg"/>
You write compiler directives in the code-behind that customize the beginning of the ResourceID per-platform.
Option 1 requires hard-coding the path, so you can't use a dynamically-assigned image, and Option 2 wrecks the whole point of trying to write cross-platform code.
WAY HUGE EDIT: May be solved
This post on the Xamarin forums made a huge difference for me: https://forums.xamarin.com/discussion/17953/helpful-shared-project-image-information
note: the first post basically gives you all the code you need, but a little bit down in the thread there's some advice about project configurations that may be necessary for it to work correctly.
It basically introduces some custom code that programmatically derives the resource ID during runtime, so it's cross-platform code that customizes itself to whatever platform is currently running it. Working beautifully for me! Here's the version of the suggested approach that I'm using:
using System.Linq;
using System.Reflection;
using System.Diagnostics;
using System;
namespace Helpers
{
public class EmbeddedSourceror
{
public static Xamarin.Forms.ImageSource SourceFor(string pclFilePathInResourceFormat)
{
var resources = typeof(EmbeddedSourceror).GetTypeInfo().Assembly.GetManifestResourceNames();
var resourceName = resources.Single(r => r.EndsWith(pclFilePathInResourceFormat, StringComparison.OrdinalIgnoreCase));
Debug.WriteLine("EmbeddedSourceror: resourceName string is " + resourceName);
return Xamarin.Forms.ImageSource.FromResource(resourceName);
}
}
}
This lets you write the Xaml code in a totally normal way, such as:
<Image
x:Name ="backingImage"
Aspect ="AspectFill" />
And in the code-behind all you have to do is:
backingImage.Source = EmbeddedSourceror.SourceFor("flower.jpg");

Unable to add longlistselector tool

I am working on a windows phone project, under a universal project. A feature I am looking for is the longlistselector template, that I am unable to find under toolbox. Am I missing something?
Or rather, if there is a way to arrange a list (of say countries), and lets say alphabetically, I wouldn't mind using that either.
VS2013 - U4; W8.1;
Thanks in advance!
There is no LongListSelector in WP8.1 RunTime/Universal app. Take a look at available controls at MSDN.
If you need a simple list, take a look at ListView.
If you need grouping, then think of using SemanticZoom. In this case you will find also some help here at blog, here or here.
LongListSelector is not available for Universal apps, it's only available for Silverlight Phone apps. Instead you can use ListView .
Example :
<phone:LongListSelector ItemsSource="{Binding Items}" >
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}">
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" >
</DataTemplate>
</ListView.ItemTemplate>
More details check this article : Migrating from the LongListSelector to the ListView in Windows Phone XAML Apps

silverlight toolkit listpicker wp7 missing icons

I'm having a problem with the listpicker (SelectionMode="Multiple"!!!). When i go to fullmode it doesnt show "done", "cancel" icons like if the images were not in my project.
On full screen mode i only have this xaml code
<DataTemplate x:Key="listPickerFullModeItemTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontSize="30" Height="40" FontFamily="Segoe WP"/>
</StackPanel>
</DataTemplate>
<toolkit:ListPicker Header="Floral" SelectionMode="Multiple" FullModeHeader="Floral" CacheMode="BitmapCache" x:Name="floralListPicker" Margin="0,0,12,0" ItemTemplate="{StaticResource listPickerItemTemplate}" FullModeItemTemplate="{StaticResource listPickerFullModeItemTemplate}"/>
Code is ok, everything works fine but the icons doesn't show, actually it shows as the default app bar missing icon image. I copied the images from toolkit sample but no go.
anyone know whats wrong?
anyway to force icons on template?
thanks.
Do you need to set the Build Action of the icons to "Content" in their properties window?
I found out the solution by exploring the sample solution of the toolkit.
If you don't use a special page for the fullmode selection, you need to include the following images to your project:
Create one subfolder named Toolkit.Content (not ToolKit/Content).
Then, include the files named as this : ApplicationBar.Cancel.png and ApplicationBar.Check.png.
Mark them to be generated as content.
That's all! Your icons should now been displayed.
Hope this helps you !

Categories