test: add fileopenpicker gallery sample
This commit is contained in:
Родитель
8b333d22b8
Коммит
ae1e3738ca
|
@ -0,0 +1,28 @@
|
|||
<Page
|
||||
x:Class="UITests.Shared.Windows_Storage.Pickers.FileOpenPickerGalleryTests"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:storage="using:Windows.Storage"
|
||||
xmlns:wasm="http://uno.ui/wasm"
|
||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
|
||||
mc:Ignorable="d wasm">
|
||||
<StackPanel Spacing="8">
|
||||
<Button Content="Select single image" Click="PickSingleFileButton_Click"/>
|
||||
<Button Content="Select multiple images" Click="PickMultipleFilesButton_Click"/>
|
||||
|
||||
<TextBlock x:Name="PickingStatus"/>
|
||||
|
||||
<ListView x:Name="SelectedFilesListView"
|
||||
Orientation="Horizontal"
|
||||
ItemsSource="{x:Bind SelectedFiles}"
|
||||
SelectionMode="None">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:DataType="storage:StorageFile">
|
||||
<Image Source="{Binding}" Width="100" Height="100"/>
|
||||
<TextBlock Text="{x:Bind Name}"/>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</StackPanel>
|
||||
</Page>
|
|
@ -0,0 +1,82 @@
|
|||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Uno;
|
||||
using Uno.Disposables;
|
||||
using Uno.Extensions;
|
||||
using Uno.UI.Samples.Controls;
|
||||
using Uno.UI.Samples.UITests.Helpers;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.Pickers;
|
||||
using Windows.UI.Core;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace UITests.Shared.Windows_Storage.Pickers;
|
||||
|
||||
[Sample("Windows.Storage",
|
||||
ViewModelType = typeof(FileOpenPickerTestsViewModel),
|
||||
IsManualTest = true,
|
||||
Description = "")]
|
||||
public sealed partial class FileOpenPickerGalleryTests : Page
|
||||
{
|
||||
public FileOpenPickerGalleryTests()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private async void PickSingleFileButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
FileOpenPicker picker = new()
|
||||
{
|
||||
picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
|
||||
};
|
||||
|
||||
picker.FileTypeFilter.Add(".jpg");
|
||||
picker.FileTypeFilter.Add(".jpeg");
|
||||
picker.FileTypeFilter.Add(".png");
|
||||
picker.FileTypeFilter.Add(".bmp");
|
||||
|
||||
var storageFile = await picker.PickSingleFileAsync();
|
||||
|
||||
if(storageFile is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using var bitmap = new BitmapImage();
|
||||
using var stream = await storageFile.OpenStreamForReadAsync()
|
||||
|
||||
await bitmap.SetSourceAsync(stream);
|
||||
stack.Children.Add(new Image() { Width=200, Height=200, Source = bitmap });
|
||||
|
||||
Status.Text = "Picked 1 image";
|
||||
|
||||
// Display file information
|
||||
Status.Text += "\n\n Info: \n";
|
||||
Status.Text += $"Name: {storageFile.Name} \n";
|
||||
Status.Text += $"Path: {storageFile.Path} \n";
|
||||
}
|
||||
|
||||
private async void PickMultipleFilesButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
FileOpenPicker picker = new()
|
||||
{
|
||||
picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
|
||||
};
|
||||
|
||||
picker.FileTypeFilter.Add(".jpg");
|
||||
picker.FileTypeFilter.Add(".jpeg");
|
||||
picker.FileTypeFilter.Add(".png");
|
||||
picker.FileTypeFilter.Add(".bmp");
|
||||
|
||||
var storageFile = await picker.PickMultipleFilesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class FileOpenPickerTestsViewModel : ViewModelBase
|
||||
{
|
||||
public ObservableCollection<CarouselItem> Items { get; } = new ObservableCollection<CarouselItem>();
|
||||
}
|
||||
|
||||
public record CarouselItem(Image Image, string Details);
|
Загрузка…
Ссылка в новой задаче