简体   繁体   English

使用 WinUI3/Project Reunion 0.5 时,我有哪些选择/打开文件和文件夹的选项?

[英]What are my options for selecting/opening files and folders when using WinUI3/Project Reunion 0.5?

There is literally no working API available which allows users to simply click a button in my app and be presented with a dialog box which would allow them to select files.实际上没有可用的 API 可用,它允许用户简单地单击我的应用程序中的一个按钮并显示一个对话框,允许他们访问 select 文件。 Am I missing something here?我在这里错过了什么吗?

Again the only answer is that you are too much of an early bird.同样,唯一的答案是你太早鸟了。

The file picker is a big problem because it's highly intervowen into the sandboxing model.文件选择器是一个大问题,因为它与沙盒 model 高度相关。 Its on the roadmap for 1.0 release together with the application activation (start from command line, start menu, clicking url, service etc.) and non sandboxed/non MSIX packaging.它在 1.0 版本的路线图上以及应用程序激活(从命令行开始、开始菜单、单击 url、服务等)和非沙盒/非 MSIX 打包。

There is COM interface called IWindowNative to get the HWND of a Window object.有一个名为 IWindowNative 的 COM 接口用于获取 Window object 的 HWND。 Unfortunately, the C#/WinRT projections need some improvements (already in-place for the Preview 2) to enable consume the COM Interfaced as it was spec'ed.不幸的是,C#/WinRT 预测需要一些改进(已经在预览版 2 中就地),以启用按照规范使用 COM 接口。

[ComImport]
        [Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1")]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        public interface IInitializeWithWindow
        {
            void Initialize(IntPtr hwnd);
        }
        [ComImport]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        [Guid("EECDBF0E-BAE9-4CB6-A68E-9598E1CB57BB")]
        internal interface IWindowNative
        {
            IntPtr WindowHandle { get; }
        }
            var filePicker = new FileOpenPicker();

            //Get the Window's HWND
            var hwnd = this.As<IWindowNative>().WindowHandle;

            //Make folder Picker work in Win32
            var initializeWithWindow = filePicker.As<IInitializeWithWindow>();
            initializeWithWindow.Initialize(hwnd);

            filePicker.FileTypeFilter.Add("*");

            var folder = await filePicker.PickSingleFileAsync();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM