Windows App SDK 1.8 ๋ฒ์ ์ด ๋ฆด๋ฆฌ์ฆ ๋์์ต๋๋ค. NuGet ๋ฉํํจํค์ง๋ก์ ๋ณํ, StoragePicker ๋ฑ์ ๊ธฐ๋ฅ์ด ํฌํจ๋ฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ๋ฆด๋ฆฌ์ฆ ๋ ธํธ์์ ํ์ธํ์ค ์ ์์ต๋๋ค.
FileOpenPicker, FileSavePicker, FolderPicker๋ WinRT์์ ํ์ผ ๋ฐ ํด๋ ์ก์ธ์ค์ ์ฌ์ฉ๋๋ API๋ก, Win32์ OpenFileDialog, SaveFileDialog, OpenFolderDialog ๋ฑ์ ๋์๋ฉ๋๋ค.
๋ฐ์คํฌํฑ ์ฑ์์ WinRT Picker API์ ํ๊ณ
Windows.Storage.Pickers ๋ค์์คํ์ด์ค์ ์์นํ๋ WinRT Picker API๋ ๋ ๊ฐ์ง์ ์ฃผ์ ํ๊ณ๊ฐ ์์ต๋๋ค.
๋จผ์ WinRT์ Picker๋ค์ ์ฑ์ด ๊ด๋ฆฌ์ ๊ถํ์ผ๋ก ์คํ ์ค์ผ ๋ ๋์ํ์ง ์์ต๋๋ค. WinRT์ Picker๋ค์ ๊ถํ ์์น ์์ด ์๋๋ฐ์ค์์ ์คํ๋๋ UWP ์ฑ์ ์ํด ์ค๊ณ๋์๊ธฐ ๋๋ฌธ์, WinUI 3 ์ฑ์ ๊ด๋ฆฌ์ ๊ถํ์ผ๋ก ์คํํ๋ฉด Picker๋ฅผ ํธ์ถํ ๋ ์์ธ๊ฐ ๋ฐ์ํฉ๋๋ค.
๋ ๋ฒ์งธ๋ก ์์ ํ Window์ ํธ๋ค๋ก Picker๋ฅผ ์ด๊ธฐํํด์ฃผ๋ ์์
์ด ํ์ํฉ๋๋ค. WinRT์ Picker๋ค์ UWP ์ฑ์ ์ํด ๋์์ธ๋ WinRT API์ธ CoreWindow์ ์์กดํ๋๋ฐ, CoreWindow๋ฅผ ๋น๋กฏํ WinRT์ ์ผ๋ถ API๋ ๋ฐ์คํฌํฑ ์ฑ์์ ์ฌ์ฉํ ์ ์๊ธฐ ๋๋ฌธ์ ๋์์ผ๋ก ์์ ํ Window์ ํธ๋ค์ ์ค์ ํด ์ค์ผ ํฉ๋๋ค.
using Windows.Storage.Pickers;
private Window _window; // picker๋ฅผ ์์ ํ๋ Window
private async Task<string> PickSingleFileAsync()
{
FileOpenPicker picker = new();
picker.FileTypeFilter.Add("*"); // ํ์
// ๋ถ๋ชจ Window์ ํธ๋ค๋ก Picker๋ฅผ ์ด๊ธฐํ
IntPtr hwnd = WinRT.Interop.WindowNative.GetWindowHandle(_window);
WinRT.Interop.InitializeWithWindow.Initialize(picker, hwnd);
var file = await picker.PickSingleFileAsync();
return file.Path;
}
Windows App SDK์์์ ํ์ผ ๋ฐ ํด๋ ์ก์ธ์ค
Windows App SDK 1.8 ๋ฒ์ ๋ถํฐ ์ถ๊ฐ๋ Microsoft.Windows.Storage.Pickers ๋ค์์คํ์ด์ค์ Picker API๋ฅผ ์ฌ์ฉํ๋ฉด, ์ด๋ฌํ ๊ณผ์ ์ ๊ฐ๋ตํ ํ ์ ์์ต๋๋ค.
using Microsoft.Windows.Storage.Pickers;
private Window _window;
private async Task<string> PickSingleFileAsync()
{
// ํธ๋ค ํ๋ ๋ฐ ์ด๊ธฐํ ๋์ ์์ฑ์์ AppWindow.Id ์ ๋ฌ
FileOpenPicker picker = new(_window.AppWindow.Id);
var result = await picker.PickSingleFileAsync();
return result.Path;
}
๋ํ WinRT์ Picker API๋ ์ฑ์ด ๊ด๋ฆฌ์ ๊ถํ์ผ๋ก ์คํ ์ค์ผ ๋ ์๋ํ์ง ์๋ ๋ฐ๋ฉด์, Windows App SDK์์ ์ถ๊ฐ๋ Picker API๋ ์ฑ์ด ๊ด๋ฆฌ์ ๊ถํ์ผ๋ก ์คํ ์ค์ผ ๋๋ ์ ์๋ํฉ๋๋ค.
WinRT์ Picker์ Windows App SDK์ Picker์ ์ฃผ์ ์ฐจ์ด์
- ๊ถํ ์์น ์ง์ ์ฌ๋ถ
- WinRT - ์ง์ํ์ง ์์(์์ธ ๋ฐ์)
- Windows App SDK - ์ง์
- ์ด๊ธฐํ ๋ฐฉ๋ฒ
- WinRT - ๋ถ๋ชจ ์๋์ฐ์ ํธ๋ค์ ํ๋ํ ํ ๋ช ์์ ์ผ๋ก ์ด๊ธฐํ
- Windows App SDK - ์์ฑ์์ ๋ถ๋ชจ ์๋์ฐ์
AppWindow.Id์ ๋ฌ
- Pick ๋ฐํ๊ฐ
- WinRT -
StorageFile,StorageFolder - Windows App SDK -
PickFileResult,PickFolderResult(string Path๋ง ๊ฐ๋ ๊ฒฝ๋ ํด๋์ค)
- WinRT -