WinUI3 でファイルを開くためのダイアログは Windows.Storage.Pickers.FileOpenPicker でした。
これ、古来よりの Microsoft.Win32.OpenFileDialog は使えないのでしょうか?
取り敢えずアッセンブリを追加してコードを書いてみますね。
参照追加
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\PresentationFramework.dll
または
C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\6.0.5\ref\net6.0\PresentationFramework.dll
■ 結果
Microsoft.Win32.OpenFileDialog を書いた部分のコードは OK でしたが別のエラーでビルドできませんでした。
無念。
■ 石器自体の ファイル選択ダイアログ
現在では失われた石器時代の技術 WinForms に一縷の望みを託してみましょう。
private void button1_Click(object sender, EventArgs e) { var fileDialog = new System.Windows.Forms.OpenFileDialog { Multiselect = false, }; if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) System.Windows.Forms.MessageBox.Show(fileDialog.FileName); else System.Windows.Forms.MessageBox.Show("選択されませんでした"); }
WinForms アッセンブル
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Windows.Forms.dll
ビルドは成功
アプリも起動
ボタンを押下(読み:おうか)
無念
無念です
無念です。