When I click on the ListItem, which is a .PDF, in my ListView, I want to save the file locally. Each ListItem has a different Uri.
Is there any way I can do that?
Currently, it's a bit tricky to implement from scratch a ListView onTap gesture - but you can use a nuget that gives that functionality for Xamarin Forms:
http://www.michaelridland.com/xamarin/freshessentials-for-xamarin-forms-the-must-have-nuget-for-forms/
Basically, in order to use it you can just add a property to your ListView and Bind it to a Command to your CodeBehind or ViewModel (if you're following an MVVM pattern or framework):
<ListView ItemsSource="{Binding MyCars}" fe:ListViewItemTappedAttached.Command="{Binding ItemTapCommand}">
Don't forget to add this resource as property/namespace of your ContentPage tho:
xmlns:fe="clr-namespace:FreshEssentials;assembly=FreshEssentials"
Ex.
<ContentPage xmlns:fe="clr-namespace:FreshEssentials;assembly=FreshEssentials" ... />
On Saving files - Because Xamarin.Forms runs on multiple platforms, each with its own filesystem, there is no single approach for loading and saving files created by the user.
You can follow this guide from Xamarin to know how to do that for every platform you are targeting: https://developer.xamarin.com/guides/xamarin-forms/working-with/files/#Loading_and_Saving_Files
Related
I have an app that is file management app like drive. I want to add sync mechanism with Xamarin Forms app.
So the sync mechanism I want is this: User will choose a folder from my app, and will choose a folder from their phone. App will sync both of them, when added a file or folder to this folders.
For example:
When a file is added to the selected folder (on the phone) from the app, this file will be uploaded to the remote server with the help of my app. Or
When a file is added to the folder (in the app) selected from the app, this file will be downloaded from the remote server to the selected folder on the phone with the help of my app.
My app will work in the background or sync will be triggered with button in my app. (Because I know ios background restricts operations. But it will be another research subject for me.)
For this reason I am looking up a folder picker. But I didn't find any plugin. When I searched, I saw that it was said that it can be done with dependency services.
So I want to get all file system structure of phone and show it with a listview for select a sync directory. I follow this documentation for get all file system structure of phone:
for ios: https://learn.microsoft.com/en-US/xamarin/ios/app-fundamentals/file-system
for android: https://learn.microsoft.com/en-US/xamarin/android/platform/files/
But I stuck in ios. Because I couldn't get all directories with this commands. For example I want to select a gallery album for sync. But I couldn't access gallery album path. I am accessing with image pickers but I don't want select a file, I want to select gallery album.
I reviewed Xamarin.Essentials Media Picker and File Picker source code in github. I also reviewed Plugin.FilePicker source code in github. All of them use UIDocumentPickerViewController or UIImagePickerController. But these for selecting file. These not selecting folder.
What can I do?
Thanks in advance.
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
Update:
You could use the code below to enumerate the subdirectories in the current directory (specified by the "./" parameter), which is the location of your application executable.
var directories = Directory.EnumerateDirectories("./");
foreach (var directory in directories) {
Console.WriteLine(directory);
}
You could check the sample code in File system access in Xamarin.iOS: https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/file-system
For more details you could refer to the link below.
https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/AccessingFilesandDirectories/AccessingFilesandDirectories.html#//apple_ref/doc/uid/TP40010672-CH3-SW1
I tried solutions from the following links but none worked.
where-to-put-images-for-xamarin-froms-application
developer.xamarin.com/guides/xamarin-forms/user-interface/images/#Local_Images
image-not-showing-in-xamarin-forms-app.html
I used below syntax
<Image Source="lock.png" HeightRequest="20" WidthRequest="20" HorizontalOptions="Center" VerticalOptions="Center" Grid.Row="0" Grid.Column="0"></Image>
Here is the image for where i've kept image
No image displays
Edit
These are the only things in my XAML page.
In my case the issue was of assembly.
when trying all the possible solutions like
1.) Changing Build Action
2.) Adding Image to all the folders within Resources
3.) Naming Convention should not include - in File/Image Name.
4.) Changing Background Color
I also got one solution while searching for embedded Images that assembly was missing here.
This change worked for me in using Local Images.
Got that solution from this link
Right click the lock.png image and see if there is an option "include in project"
If there is, project cannot find image
In my case I need to use method Forms.Init(Context activity, Bundle bundle), in my SplashScreen OnCreate method and Activity class OnCreate method. But it also important that images build action properties is set on AndroidResource.
I need the picker page from the toolkit's datepicker control to be in spanish. I tried a few approaches found here on SO, but they didn't work for me.
One thing a noticed is that when i run the sample app from the toolkit, the picker page is localized, but when i run my app which uses the same dll, it does not.
So the question is, what is doing the sample app, that mine doesn't in order for the picker page to be localized?
My DatePicker declaration:
<toolkit:DatePicker Width="280" Background="#96CA04" Foreground="White" Value=" {Binding LeagueBegDate,Mode=TwoWay}" />
Sample App DAtePicker declaration:
<toolkit:DatePicker ValueChanged="DatePicker_ValueChanged"/>
What i had to do was, to open the .csproj file of my project and add es-ES; entry under the <SupportedCultures> node.
I did try adding just es;, but it didn't work. It had to be es-ES; as in the toolkit project, under the LocalizedResources folder the resx files is called: ControlResources.es-ES.resx.
So the entry ended up looking like this:
<SupportedCultures>
es; es-ES;
</SupportedCultures>
To clarify, i did not have to add a localized resources file in my project, just added the supported cultures and the toolkit's localization kicked in.
I'm attempting to localize my WinRT app. I don't need anything too fancy, so I've been using x:Uid on XAML elements in conjunction with resource files that have properties such as "PageTitleTextBox.Text" set. This method was working great until I ran into an issue with attached properties.
I've defined a few app bar buttons using similar markup to what I've seen in other examples:
<Button x:Name="AddFolderButton" Click="AddFolderButton_Tapped" x:Uid="FoldersPageAppBarAddFolderButton" AutomationProperties.Name="Test" Style="{StaticResource AppBarButtonStyle}">
<Button.Content></Button.Content>
</Button >
In this case, I'd like to localize AddFolderButton's label, currently defined by AutomationProperties.Name. I tried setting a key in my resource file to FoldersPageAppBarAddFolderButton.AutomationProperties.Name, but this fails on runtime.
Is it possible to localize this label using XAML, or do I need to do this programatically in the code-behind file?
You need to handle attached properties a bit differently, i.e. their namespace must be included in the reource key like this:
FoldersPageAppBarAddFolderButton.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name
You can read more about it here.
After being advised that the native ComboBox was not the way to go I was told to look at the Silverlight Toolkit ListPicker. So I did and have got a problem.
I opened a new project and pulled a new ListPicker onto the MainPage. The ListPicker looks like:
<toolkit:ListPicker x:Name="Result">
<toolkit:ListPickerItem Content="Win" />
<toolkit:ListPickerItem Content="Place" />
<toolkit:ListPickerItem Content="Lose" />
</toolkit:ListPicker>
When trying to run this I get an XamlParseException with InnerException of InvalidProgramException. All I did was drag the control on, and add some ListPickerItem. Removing the items still results in the error, removing the ListPicker control completely allows the page to be shown with no error.
I'm sure I've missed something, but any documentation I have read seems to point towards this markup being fine, including http://windowsphonegeek.com/articles/listpicker-for-wp7-in-depth
I can provide any other info required.
ListPickerItem is a class used internally by the ListPicker and should not be used directly.
If you just want to add a list of items, you can use strings to do it, like this:
Add a new namespace on top of the Page to access the String class:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Then, just change the ListPicker code to this:
<toolkit:ListPicker>
<sys:String>Win</sys:String>
<sys:String>Place</sys:String>
<sys:String>Lose</sys:String>
</toolkit:ListPicker>
The problem was that the wrong dlls had been registered, i.e. 7 and not 7.1. I had to uninstall and reinstall to get it to update correctly and it worked.