我正在使用Xamarin.Forms
应用。我需要浏览并打开文件夹中的文件,当我尝试这样做并选择文件时,文件路径不会显示在输入行中。这是我的代码,请告诉我应该改变什么?
public string FileName
{
get { return fileName; }
set
{
fileName = value;
PropertyChanged(this, new PropertyChangedEventArgs("csv_file"));
}
}
private Plugin.FilePicker.Abstractions.FileData file = default(Plugin.FilePicker.Abstractions.FileData);
public async void OnBrowse(object o, EventArgs args)
{
this.file = await CrossFilePicker.Current.PickFile();
if (this.file == null)
{
return;
}
string extensionType = this.file.FileName.Substring(this.file.FileName.LastIndexOf(".", StringComparison.Ordinal)
+ 1, this.file.FileName.Length - this.file.FileName.LastIndexOf(".", StringComparison.Ordinal) - 1).ToLower();
if (extensionType.Equals("csv"))
{
csv_file.SetValue((BindableProperty.Create("csv_file", typeof(string), typeof(Entry), null, BindingMode.TwoWay, null)), fileName);
}
else
{
await this.DisplayAlert("Name of the file:" + file.FileName + " and path too file: " + file.FilePath, "File info", "OK");
}
}
这是xaml代码
<StackLayout Orientation="Horizontal"
HorizontalOptions="FillAndExpand">
<Entry x:Name="csv_file" Placeholder="" WidthRequest="150">
</Entry>
<Button BackgroundColor="Gray" TextColor="Black"
WidthRequest="40" Text="...." Clicked="OnBrowse"/>
</StackLayout>