diff --git a/Samples/CameraCaptureUI/cpp-winui/cpp-winui/pch.h b/Samples/CameraCaptureUI/cpp-winui/cpp-winui/pch.h index ceec9a7cc..35021a09f 100644 --- a/Samples/CameraCaptureUI/cpp-winui/cpp-winui/pch.h +++ b/Samples/CameraCaptureUI/cpp-winui/cpp-winui/pch.h @@ -32,7 +32,7 @@ #include "winrt/Microsoft.UI.Windowing.h" #include "winrt/Windows.ApplicationModel.h" #include "Winrt/Microsoft.UI.Xaml.Media.Imaging.h" -#include +#include #include #include #include diff --git a/Samples/Composition/DynamicRefreshRateTool/cpp-winui/MainWindow.xaml.cpp b/Samples/Composition/DynamicRefreshRateTool/cpp-winui/MainWindow.xaml.cpp index 52f91d361..dc49daa6f 100644 --- a/Samples/Composition/DynamicRefreshRateTool/cpp-winui/MainWindow.xaml.cpp +++ b/Samples/Composition/DynamicRefreshRateTool/cpp-winui/MainWindow.xaml.cpp @@ -82,16 +82,16 @@ namespace winrt::DynamicRefreshRateTool::implementation winrt::Windows::Foundation::IAsyncAction MainWindow::ChooseFolder_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e) { - Windows::Storage::Pickers::FolderPicker picker; - picker.ViewMode(Windows::Storage::Pickers::PickerViewMode::List); - picker.SuggestedStartLocation(Windows::Storage::Pickers::PickerLocationId::ComputerFolder); - picker.as()->Initialize(GetActiveWindow()); + Microsoft::Windows::Storage::Pickers::FolderPicker picker{ this->AppWindow().Id() }; + picker.ViewMode(Microsoft::Windows::Storage::Pickers::PickerViewMode::List); + picker.SuggestedStartLocation(Microsoft::Windows::Storage::Pickers::PickerLocationId::ComputerFolder); - - if (auto loggingFolder = co_await picker.PickSingleFolderAsync()) + if (auto result = co_await picker.PickSingleFolderAsync()) { - m_loggingFolder = loggingFolder; - FolderPath().Text(m_loggingFolder.Path()); + // Store the picked folder path directly as a string + auto folderPath = result.Path(); + m_loggingFolderPath = std::wstring{ folderPath }; + FolderPath().Text(folderPath); FolderPath().Visibility(Visibility::Visible); FolderNotSelected().Visibility(Visibility::Collapsed); LoggingToggleSwitch().IsEnabled(true); @@ -114,7 +114,7 @@ namespace winrt::DynamicRefreshRateTool::implementation void MainWindow::StartLogging() { - m_logger.emplace(std::wstring(m_loggingFolder.Path().c_str())); + m_logger.emplace(m_loggingFolderPath); } void MainWindow::StopLogging() diff --git a/Samples/Composition/DynamicRefreshRateTool/cpp-winui/MainWindow.xaml.h b/Samples/Composition/DynamicRefreshRateTool/cpp-winui/MainWindow.xaml.h index 44cd271c3..9869cfe94 100644 --- a/Samples/Composition/DynamicRefreshRateTool/cpp-winui/MainWindow.xaml.h +++ b/Samples/Composition/DynamicRefreshRateTool/cpp-winui/MainWindow.xaml.h @@ -39,7 +39,7 @@ namespace winrt::DynamicRefreshRateTool::implementation bool IsLogging(); std::optional m_logger; - winrt::Windows::Storage::StorageFolder m_loggingFolder = nullptr; + std::wstring m_loggingFolderPath; std::future m_updateFuture; bool running = true; diff --git a/Samples/Composition/DynamicRefreshRateTool/cpp-winui/pch.h b/Samples/Composition/DynamicRefreshRateTool/cpp-winui/pch.h index b06c6d0cc..f7d003a20 100644 --- a/Samples/Composition/DynamicRefreshRateTool/cpp-winui/pch.h +++ b/Samples/Composition/DynamicRefreshRateTool/cpp-winui/pch.h @@ -55,7 +55,7 @@ #include #include -#include +#include #include #include diff --git a/Samples/PhotoEditor/cpp-winui/PhotoEditor/DetailPage.xaml.cpp b/Samples/PhotoEditor/cpp-winui/PhotoEditor/DetailPage.xaml.cpp index ee9e5d7bb..dfafc029b 100644 --- a/Samples/PhotoEditor/cpp-winui/PhotoEditor/DetailPage.xaml.cpp +++ b/Samples/PhotoEditor/cpp-winui/PhotoEditor/DetailPage.xaml.cpp @@ -27,7 +27,7 @@ namespace winrt using namespace Windows::Graphics::Effects; using namespace Windows::Graphics::Imaging; using namespace Windows::Storage; - using namespace Windows::Storage::Pickers; + using namespace Microsoft::Windows::Storage::Pickers; using namespace Windows::Storage::Search; using namespace Windows::Storage::Streams; using namespace Windows::UI; @@ -576,13 +576,18 @@ namespace winrt::PhotoEditor::implementation IAsyncAction DetailPage::SaveButton_Click(IInspectable const&, RoutedEventArgs const&) { - // Setup the picker. - auto picker = FileSavePicker{}; + auto picker = FileSavePicker{ App::Window().AppWindow().Id() }; picker.SuggestedStartLocation(PickerLocationId::PicturesLibrary); picker.SuggestedFileName(L"New Image"); picker.FileTypeChoices().Insert(L"Images", winrt::single_threaded_vector({ L".jpg" })); - if (auto file = co_await picker.PickSaveFileAsync()) + auto result = co_await picker.PickSaveFileAsync(); + if (!result) + { + return; + } + + if (auto file = co_await Windows::Storage::StorageFile::GetFileFromPathAsync(result.Path())) { if (auto stream = co_await file.OpenAsync(Windows::Storage::FileAccessMode::ReadWrite)) { diff --git a/Samples/PhotoEditor/cpp-winui/PhotoEditor/pch.h b/Samples/PhotoEditor/cpp-winui/PhotoEditor/pch.h index 69585b6a8..37a3e7395 100644 --- a/Samples/PhotoEditor/cpp-winui/PhotoEditor/pch.h +++ b/Samples/PhotoEditor/cpp-winui/PhotoEditor/pch.h @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Samples/PhotoEditor/cs-winui/DetailPage.xaml.cs b/Samples/PhotoEditor/cs-winui/DetailPage.xaml.cs index 51b03e6ff..8649d4e76 100644 --- a/Samples/PhotoEditor/cs-winui/DetailPage.xaml.cs +++ b/Samples/PhotoEditor/cs-winui/DetailPage.xaml.cs @@ -5,10 +5,12 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.IO; +using System.Runtime.InteropServices.WindowsRuntime; using System.Threading.Tasks; using Windows.Storage; -using Windows.Storage.Pickers; using Windows.Storage.Streams; +using Microsoft.Windows.Storage.Pickers; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Media.Animation; @@ -205,18 +207,22 @@ private async void ExportImage() ds.DrawImage(img); } - - var fileSavePicker = new FileSavePicker() + var fileSavePicker = new FileSavePicker(App.WindowId) { SuggestedStartLocation = PickerLocationId.PicturesLibrary, - SuggestedSaveFile = item.ImageFile + SuggestedFileName = item.ImageFile.DisplayName, + SuggestedFolder = await item.ImageFile.GetParentAsync().Path, + FileTypeChoices = { + {"JPEG files", new[] { ".jpg" }}, + }, }; - fileSavePicker.FileTypeChoices.Add("JPEG files", new List() { ".jpg" }); - - WinRT.Interop.InitializeWithWindow.Initialize(fileSavePicker, App.WindowHandle); - - var outputFile = await fileSavePicker.PickSaveFileAsync(); + var result = await fileSavePicker.PickSaveFileAsync(); + StorageFile outputFile; + if (result) + { + outputFile = await StorageFile.GetFileFromPathAsync(result.Path); + } if (outputFile != null) { diff --git a/Samples/SceneGraph/Demos/MaterialCreator/MaterialCreatorApp/Controls/EditLayerControl.xaml.cs b/Samples/SceneGraph/Demos/MaterialCreator/MaterialCreatorApp/Controls/EditLayerControl.xaml.cs index f995c22b4..cecab549a 100644 --- a/Samples/SceneGraph/Demos/MaterialCreator/MaterialCreatorApp/Controls/EditLayerControl.xaml.cs +++ b/Samples/SceneGraph/Demos/MaterialCreator/MaterialCreatorApp/Controls/EditLayerControl.xaml.cs @@ -20,8 +20,7 @@ using System.Diagnostics; using System.Linq; using System.Reflection; -using Windows.Storage; -using Windows.Storage.Pickers; +using Microsoft.Windows.Storage.Pickers; using Microsoft.UI.Composition.Effects; using Microsoft.UI.Xaml.Hosting; @@ -228,19 +227,20 @@ private void UpdateEdgeModeProperties(StackPanel panel, ImageLayer layer) private async void Button_Click(object sender, RoutedEventArgs e) { - FileOpenPicker openPicker = new FileOpenPicker(); - openPicker.ViewMode = PickerViewMode.Thumbnail; - openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; - openPicker.FileTypeFilter.Add(".jpg"); - openPicker.FileTypeFilter.Add(".jpeg"); - openPicker.FileTypeFilter.Add(".png"); - WinRT.Interop.InitializeWithWindow.Initialize(openPicker, WinRT.Interop.WindowNative.GetWindowHandle(MainWindow.CurrentWindow)); - StorageFile file = await openPicker.PickSingleFileAsync(); - - if (file != null) + var openPicker = new FileOpenPicker(MainWindow.CurrentWindow.AppWindow.Id) { - Filename.Text = file.Name; - ((ImageLayer)Layer).File = file; + ViewMode = PickerViewMode.Thumbnail, + SuggestedStartLocation = PickerLocationId.PicturesLibrary, + FileTypeFilter = { ".jpg", ".jpeg", ".png" } + }; + + var result = await openPicker.PickSingleFileAsync(); + + if (result != null) + { + Filename.Text = System.IO.Path.GetFileName(result.Path); + ((ImageLayer)Layer).FilePath = result.Path; + await ((ImageLayer)Layer).LoadResources(); } } diff --git a/Samples/SceneGraph/Demos/MaterialCreator/MaterialCreatorApp/MainPage.xaml.cs b/Samples/SceneGraph/Demos/MaterialCreator/MaterialCreatorApp/MainPage.xaml.cs index a9b5ee99a..a269c4c81 100644 --- a/Samples/SceneGraph/Demos/MaterialCreator/MaterialCreatorApp/MainPage.xaml.cs +++ b/Samples/SceneGraph/Demos/MaterialCreator/MaterialCreatorApp/MainPage.xaml.cs @@ -27,10 +27,11 @@ using System.ComponentModel; using System.Diagnostics; using System.Reflection; +using System.IO; using SamplesCommon; using Windows.Foundation; using Windows.UI; -using Windows.Storage.Pickers; +using Microsoft.Windows.Storage.Pickers; using Windows.Storage; using Windows.Storage.Streams; using Windows.Graphics.Effects; @@ -221,20 +222,24 @@ private async void BackgroundCombo_SelectionChanged(object sender, SelectionChan } else { - FileOpenPicker openPicker = new FileOpenPicker(); - openPicker.ViewMode = PickerViewMode.Thumbnail; - openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; - openPicker.FileTypeFilter.Add(".jpg"); - openPicker.FileTypeFilter.Add(".jpeg"); - openPicker.FileTypeFilter.Add(".png"); - WinRT.Interop.InitializeWithWindow.Initialize(openPicker, WinRT.Interop.WindowNative.GetWindowHandle(MainWindow.CurrentWindow)); - StorageFile file = await openPicker.PickSingleFileAsync(); - - if (file != null) + var openPicker = new FileOpenPicker(MainWindow.CurrentWindow.AppWindow.Id) + { + ViewMode = PickerViewMode.Thumbnail, + SuggestedStartLocation = PickerLocationId.PicturesLibrary, + FileTypeFilter = { ".jpg", ".jpeg", ".png" }, + }; + + var result = await openPicker.PickSingleFileAsync(); + if (result != null) { BitmapImage bitmapImage = new BitmapImage(); - IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read); - bitmapImage.SetSource(stream); + + // Use System.IO to create a file stream directly from the path + using (var fileStream = File.OpenRead(result.Path)) + { + var randomAccessStream = fileStream.AsRandomAccessStream(); + await bitmapImage.SetSourceAsync(randomAccessStream); + } PreviewPanel.Background = new ImageBrush() { diff --git a/Samples/SceneGraph/Demos/MaterialCreator/MaterialCreatorApp/Model/Layers/ImageLayer.cs b/Samples/SceneGraph/Demos/MaterialCreator/MaterialCreatorApp/Model/Layers/ImageLayer.cs index 35f9b35dc..9ef3d002b 100644 --- a/Samples/SceneGraph/Demos/MaterialCreator/MaterialCreatorApp/Model/Layers/ImageLayer.cs +++ b/Samples/SceneGraph/Demos/MaterialCreator/MaterialCreatorApp/Model/Layers/ImageLayer.cs @@ -29,7 +29,7 @@ using System.Threading.Tasks; using Windows.Foundation; using Windows.Storage; -using Windows.Storage.Pickers; +using Microsoft.Windows.Storage.Pickers; namespace MaterialCreator { @@ -115,14 +115,19 @@ private async Task LoadFromFilePath(string filePath) await dialog.ShowAsync(); // Launch the picker - FileOpenPicker openPicker = new FileOpenPicker(); - openPicker.ViewMode = PickerViewMode.Thumbnail; - openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; - openPicker.FileTypeFilter.Add(".jpg"); - openPicker.FileTypeFilter.Add(".jpeg"); - openPicker.FileTypeFilter.Add(".png"); - WinRT.Interop.InitializeWithWindow.Initialize(openPicker, WinRT.Interop.WindowNative.GetWindowHandle(MainWindow.CurrentWindow)); - return await openPicker.PickSingleFileAsync(); + var openPicker = new FileOpenPicker(MainWindow.CurrentWindow.AppWindow.Id) + { + ViewMode = PickerViewMode.Thumbnail, + SuggestedStartLocation = PickerLocationId.PicturesLibrary, + FileTypeFilter = { ".jpg", ".jpeg", ".png" }, + }; + + var newResult = await openPicker.PickSingleFileAsync(); + if (newResult != null && !string.IsNullOrEmpty(newResult.Path)) + { + return await StorageFile.GetFileFromPathAsync(newResult.Path); + } + return null; } else { diff --git a/Samples/SceneGraph/SampleGalleryApp/Samples/VideoPlayground/VideoPlaygroundViewModel.cs b/Samples/SceneGraph/SampleGalleryApp/Samples/VideoPlayground/VideoPlaygroundViewModel.cs index 26beaada5..0aafbedea 100644 --- a/Samples/SceneGraph/SampleGalleryApp/Samples/VideoPlayground/VideoPlaygroundViewModel.cs +++ b/Samples/SceneGraph/SampleGalleryApp/Samples/VideoPlayground/VideoPlaygroundViewModel.cs @@ -13,7 +13,7 @@ //********************************************************* using Windows.Storage; -using Windows.Storage.Pickers; +using Microsoft.Windows.Storage.Pickers; using Microsoft.UI.Composition; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Hosting; @@ -246,14 +246,17 @@ private void OpenFile(object obj) /// StorageFile that contains the selected video. private async Task OpenFile() { - var picker = new FileOpenPicker(); - picker.ViewMode = PickerViewMode.Thumbnail; - picker.SuggestedStartLocation = PickerLocationId.VideosLibrary; - // We could technically support more formats, all we would have to do is add them - // to the FileTypeFilter colleciton. For now we'll just use mp4 files. - picker.FileTypeFilter.Add(".mp4"); - - return await picker.PickSingleFileAsync(); + var picker = new FileOpenPicker(default) + { + ViewMode = PickerViewMode.Thumbnail, + SuggestedStartLocation = PickerLocationId.VideosLibrary, + // We could technically support more formats, all we would have to do is add them + // to the FileTypeFilter colleciton. For now we'll just use mp4 files. + FileTypeFilter = { ".mp4" }, + }; + + var result = await picker.PickSingleFileAsync(); + return await StorageFile.CreateFromPathAsync(result.Path); } /// diff --git a/Samples/WindowsAIFoundry/cs-winui/ViewModels/InputImageViewModelBase.cs b/Samples/WindowsAIFoundry/cs-winui/ViewModels/InputImageViewModelBase.cs index 066a50251..77e75461a 100644 --- a/Samples/WindowsAIFoundry/cs-winui/ViewModels/InputImageViewModelBase.cs +++ b/Samples/WindowsAIFoundry/cs-winui/ViewModels/InputImageViewModelBase.cs @@ -3,12 +3,12 @@ using WindowsAISample.Models.Contracts; using WindowsAISample.Util; +using Microsoft.Windows.Storage.Pickers; using Microsoft.UI.Xaml.Media.Imaging; using System; using System.Threading.Tasks; using System.Windows.Input; using Windows.Graphics.Imaging; -using Windows.Storage.Pickers; using Windows.Storage.Streams; using WinRT.Interop; @@ -48,18 +48,20 @@ await DispatcherQueue.EnqueueAsync(async () => _pickInputImageCommand = new(async _ => { - var picker = new FileOpenPicker(); - var window = App.Window; - var hwnd = WindowNative.GetWindowHandle(window); - InitializeWithWindow.Initialize(picker, hwnd); - - picker.ViewMode = PickerViewMode.Thumbnail; - picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; - picker.FileTypeFilter.Add(".jpg"); - picker.FileTypeFilter.Add(".jpeg"); - picker.FileTypeFilter.Add(".png"); - - var file = await picker.PickSingleFileAsync(); + var picker = new FileOpenPicker(App.window.Id) + { + ViewMode = PickerViewMode.Thumbnail, + SuggestedStartLocation = PickerLocationId.PicturesLibrary, + FileTypeFilter = { ".jpg", ".jpeg", ".png" }, + }; + + var result = await picker.PickSingleFileAsync(); + if (result == null) + { + return false; + } + + var file = await StorageFile.CreateFromPathAsync(result.Path); if (file != null) { using (IRandomAccessStream readStream = await file.OpenReadAsync()) @@ -79,18 +81,20 @@ await DispatcherQueue.EnqueueAsync(async () => _pickMaskImageCommand = new(async _ => { - var picker = new FileOpenPicker(); - var window = App.Window; - var hwnd = WindowNative.GetWindowHandle(window); - InitializeWithWindow.Initialize(picker, hwnd); - - picker.ViewMode = PickerViewMode.Thumbnail; - picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; - picker.FileTypeFilter.Add(".jpg"); - picker.FileTypeFilter.Add(".jpeg"); - picker.FileTypeFilter.Add(".png"); - - var file = await picker.PickSingleFileAsync(); + var picker = new FileOpenPicker(App.Windows.Id) + { + ViewMode = PickerViewMode.Thumbnail, + SuggestedStartLocation = PickerLocationId.PicturesLibrary, + FileTypeFilter = { ".jpg", ".jpeg", ".png" }, + }; + + var result = await picker.PickSingleFileAsync(); + if (result == null) + { + return false; + } + + var file = await StorageFile.CreateFromPathAsync(result.Path); if (file != null) { using (IRandomAccessStream readStream = await file.OpenReadAsync()) diff --git a/Samples/WindowsAIFoundry/cs-winui/ViewModels/LanguageModelViewModel.cs b/Samples/WindowsAIFoundry/cs-winui/ViewModels/LanguageModelViewModel.cs index 1878f8a48..55ddedd5d 100644 --- a/Samples/WindowsAIFoundry/cs-winui/ViewModels/LanguageModelViewModel.cs +++ b/Samples/WindowsAIFoundry/cs-winui/ViewModels/LanguageModelViewModel.cs @@ -2,11 +2,11 @@ // Licensed under the MIT License. using Microsoft.Windows.AI.ContentSafety; using Microsoft.Windows.AI.Text; +using Microsoft.Windows.Storage.Pickers; using System; using System.Collections.ObjectModel; using System.Text; using System.Windows.Input; -using Windows.Storage.Pickers; using WindowsAISample.Models; using WindowsAISample.Util; using WinRT.Interop; @@ -217,16 +217,20 @@ public LanguageModelViewModel(LanguageModelModel languageModelSession) _pickInputAdapterCommand = new(async _ => { - var picker = new FileOpenPicker(); - var window = App.Window; - var hwnd = WindowNative.GetWindowHandle(window); - InitializeWithWindow.Initialize(picker, hwnd); + var picker = new FileOpenPicker(App.Window.Id) + { + ViewMode = PickerViewMode.List, + SuggestedStartLocation = PickerLocationId.DocumentsLibrary, + FileTypeFilter = { ".safetensors" }, + }; - picker.ViewMode = PickerViewMode.List; - picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; - picker.FileTypeFilter.Add(".safetensors"); + var result = await picker.PickSingleFileAsync(); + if (result == null) + { + return false; + } - var file = await picker.PickSingleFileAsync(); + var file = await StorageFile.CreateFromPathAsync(result.Path); if (file != null) { await DispatcherQueue.EnqueueAsync(() =>