You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
51 lines
1.5 KiB
using AIK.Common.Interface;
|
|
using Ookii.Dialogs.Wpf;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace AIKKey.Infrastructure
|
|
{
|
|
public class WpfFileDialogService : IFileDialogService
|
|
{
|
|
public Task<string?> OpenFileAsync(string title = "选择文件")
|
|
{
|
|
return Task.Run(() =>
|
|
{
|
|
var dialog = new VistaOpenFileDialog
|
|
{
|
|
Title = title,
|
|
Multiselect = false
|
|
};
|
|
|
|
// 必须在 STA 线程(WPF 主线程)运行
|
|
return Application.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
bool? result = dialog.ShowDialog();
|
|
return result == true ? dialog.FileName : null;
|
|
});
|
|
});
|
|
}
|
|
|
|
public Task<string?> SelectFolderAsync(string description = "请选择文件夹")
|
|
{
|
|
return Task.Run(() =>
|
|
{
|
|
var dialog = new VistaFolderBrowserDialog
|
|
{
|
|
Description = description,
|
|
UseDescriptionForTitle = true
|
|
};
|
|
|
|
return Application.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
bool? result = dialog.ShowDialog();
|
|
return result == true ? dialog.SelectedPath : null;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|