feat: enhance FileChooser demo.
(cherry picked from commit e4c21aefc69984af7fcd807abd3f2f3310e5bbb1)
This commit is contained in:
parent
5161331b98
commit
1d975fa734
@ -8,8 +8,13 @@
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
<StackPanel HorizontalAlignment="Left" Spacing="10">
|
||||
<Button Name="openFileDialog">Open File</Button>
|
||||
<Button Name="selectFolderDialog">Select Folder</Button>
|
||||
<Button Name="saveFileDialog">Save File</Button>
|
||||
<StackPanel.Styles>
|
||||
<Style Selector="Button">
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
</Style>
|
||||
</StackPanel.Styles>
|
||||
<Button Name="OpenFileButton" Content="Open File" />
|
||||
<Button Name="SelectFolderButton" Content="Select Folder" />
|
||||
<Button Name="SaveFileButton" Content="Save File" />
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Dialogs;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Platform.Storage;
|
||||
|
||||
namespace Semi.Avalonia.Demo.Pages;
|
||||
@ -14,14 +10,14 @@ public partial class ManagedFileChooserDemo : UserControl
|
||||
public ManagedFileChooserDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
openFileDialog.Click += OpenFileDialog;
|
||||
selectFolderDialog.Click += SelectFolderDialog;
|
||||
saveFileDialog.Click += SaveFileDialog;
|
||||
OpenFileButton.Click += OpenFileDialog;
|
||||
SelectFolderButton.Click += SelectFolderDialog;
|
||||
SaveFileButton.Click += SaveFileDialog;
|
||||
}
|
||||
|
||||
private async void OpenFileDialog(object sender, RoutedEventArgs args)
|
||||
private async void OpenFileDialog(object? sender, RoutedEventArgs args)
|
||||
{
|
||||
IStorageProvider? sp = GetStorageProvider();
|
||||
var sp = GetStorageProvider();
|
||||
if (sp is null) return;
|
||||
var result = await sp.OpenFilePickerAsync(new FilePickerOpenOptions()
|
||||
{
|
||||
@ -30,9 +26,10 @@ public partial class ManagedFileChooserDemo : UserControl
|
||||
AllowMultiple = true,
|
||||
});
|
||||
}
|
||||
private async void SelectFolderDialog(object sender, RoutedEventArgs args)
|
||||
|
||||
private async void SelectFolderDialog(object? sender, RoutedEventArgs args)
|
||||
{
|
||||
IStorageProvider? sp = GetStorageProvider();
|
||||
var sp = GetStorageProvider();
|
||||
if (sp is null) return;
|
||||
var result = await sp.OpenFolderPickerAsync(new FolderPickerOpenOptions()
|
||||
{
|
||||
@ -40,13 +37,14 @@ public partial class ManagedFileChooserDemo : UserControl
|
||||
AllowMultiple = true,
|
||||
});
|
||||
}
|
||||
private async void SaveFileDialog(object sender, RoutedEventArgs args)
|
||||
|
||||
private async void SaveFileDialog(object? sender, RoutedEventArgs args)
|
||||
{
|
||||
IStorageProvider? sp = GetStorageProvider();
|
||||
var sp = GetStorageProvider();
|
||||
if (sp is null) return;
|
||||
var result = await sp.SaveFilePickerAsync(new FilePickerSaveOptions()
|
||||
{
|
||||
Title = "Open File",
|
||||
Title = "Save File",
|
||||
});
|
||||
}
|
||||
|
||||
@ -58,10 +56,10 @@ public partial class ManagedFileChooserDemo : UserControl
|
||||
|
||||
List<FilePickerFileType>? GetFileTypes()
|
||||
{
|
||||
return new List<FilePickerFileType>
|
||||
{
|
||||
return
|
||||
[
|
||||
FilePickerFileTypes.All,
|
||||
FilePickerFileTypes.TextPlain
|
||||
};
|
||||
];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user