使用DispatcherHelper类执行对话框操作。
示例如下:
using Avalonia;
using Avalonia.Controls;
using Avalonia.Threading;
using ReactiveUI;
public class MainWindowViewModel : ReactiveObject
{
public ReactiveCommand SelectFolderCommand { get; }
public MainWindowViewModel()
{
SelectFolderCommand = ReactiveCommand.CreateFromTask(SelectFolder);
}
private async Task SelectFolder()
{
var dialog = new OpenFolderDialog();
// 使用DispatcherHelper类执行对话框操作
var result = await Dispatcher.UIThread.InvokeAsync(() => dialog.ShowAsync(App.GetCurrentWindow()));
if (result != null)
{
// 处理选择的文件夹
}
}
}