You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Everything is all right If you use this:
private async void OpenButton_Click(object sender, RoutedEventArgs e)
{
//https://github.com/microsoft/WindowsAppSDK/issues/1188
//More info on obtaining the HWND
var filePicker = new FileOpenPicker();
// Get the current window's HWND by passing in the Window object
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
// Associate the HWND with the file picker
WinRT.Interop.InitializeWithWindow.Initialize(filePicker, hwnd);
// Use file picker like normal!
filePicker.FileTypeFilter.Add("*");
var file = await filePicker.PickSingleFileAsync();
if (file != null)
{
using (Windows.Storage.Streams.IRandomAccessStream randAccStream =
await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
// Load the file into the Document property of the RichEditBox.
editor.Document.LoadFromStream(Microsoft.UI.Text.TextSetOptions.FormatRtf, randAccStream);
}
}
}
instead of this:
private async void OpenButton_Click(object sender, RoutedEventArgs e)
{
//https://github.com/microsoft/WindowsAppSDK/issues/1188
//More info on obtaining the HWND
var filePicker = new FileOpenPicker();
// Get the current window's HWND by passing in the Window object
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
// Associate the HWND with the file picker
WinRT.Interop.InitializeWithWindow.Initialize(filePicker, hwnd);
// Use file picker like normal!
filePicker.FileTypeFilter.Add("*");
var file = await filePicker.PickSingleFileAsync();
if (file != null)
{
using (Windows.Storage.Streams.IRandomAccessStream randAccStream =
await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
// Load the file into the Document property of the RichEditBox.
editor.Document.LoadFromStream(Microsoft.UI.Text.TextSetOptions.FormatRtf, randAccStream);
}
}
}
Which version of the app?
WinUI 3 Gallery
Description
Source: Windows.Storage.StorageFile file = await open.PickSingleFileAsync();
VS2022: System.Runtime.InteropServices.COMException: 'Invalid window handle. (0x80070578)
Consider WindowNative, InitializeWithWindow
See https://aka.ms/cswinrt/interop#windows-sdk'
Screenshots
Windows version
Windows 11 22H2 (22621)
Additional context
Edition Windows 11 Home
Version 23H2
Installed on 9/11/2023
OS build 22631.2861
Experience Windows Feature Experience Pack 1000.22681.1000.0
Processor 13th Gen Intel(R) Core(TM) i9-13900H 2.60 GHz
Installed RAM 16.0 GB (15.6 GB usable)
System type 64-bit operating system, x64-based processor
Pen and touch No pen or touch input is available for this display
The text was updated successfully, but these errors were encountered: