[英]Can't find Win32 assembly for OpenfileDialog in WPF Framework 4.5.2
我嘗試在.NET4.5.2的WPF項目中編寫“打開/保存文件對話框”的代碼。 我找到了基於Win32.OpenFileDialog的解決方案。
我使用Win8.1(x64),但在Visual Studio 2015社區的程序集中找不到任何Win32條目。
有可以下載檔案的地方嗎? 我該如何以其他方式管理我的“打開/保存對話框”?
我相信它在PresentationFramework
程序集中:
namespace Microsoft.Win32
{
//
// Summary:
// Represents a common dialog box that allows a user to specify a filename for one
// or more files to open.
public sealed class OpenFileDialog : FileDialog
{
//
// Summary:
// Initializes a new instance of the Microsoft.Win32.OpenFileDialog class.
[SecurityCritical]
public OpenFileDialog();
//
// Summary:
// Gets or sets an option indicating whether Microsoft.Win32.OpenFileDialog allows
// users to select multiple files.
//
// Returns:
// true if multiple selections are allowed; otherwise, false. The default is false.
public bool Multiselect { get; set; }
//
// Summary:
// Gets or sets a value indicating whether the read-only check box displayed by
// Microsoft.Win32.OpenFileDialog is selected.
//
// Returns:
// true if the checkbox is selected; otherwise, false. The default is false.
public bool ReadOnlyChecked { get; set; }
//
// Summary:
// Gets or sets a value indicating whether Microsoft.Win32.OpenFileDialog contains
// a read-only check box.
//
// Returns:
// true if the checkbox is displayed; otherwise, false. The default is false.
public bool ShowReadOnly { get; set; }
//
// Summary:
// Opens a read-only stream for the file that is selected by the user using Microsoft.Win32.OpenFileDialog.
//
// Returns:
// A new System.IO.Stream that contains the selected file.
//
// Exceptions:
// T:System.InvalidOperationException:
// No files were selected in the dialog.
[SecurityCritical]
public Stream OpenFile();
//
// Summary:
// Creates an array that contains one read-only stream for each file selected by
// the user using Microsoft.Win32.OpenFileDialog.
//
// Returns:
// An array of multiple new System.IO.Stream objects that contain the selected files.
//
// Exceptions:
// T:System.InvalidOperationException:
// No files were selected in the dialog.
[SecurityCritical]
public Stream[] OpenFiles();
//
// Summary:
// Resets all Microsoft.Win32.OpenFileDialog properties to their default values.
[SecurityCritical]
public override void Reset();
[SecurityCritical]
[SecurityTreatAsSafe]
protected override void CheckPermissionsToShowDialog();
}
}
如果需要更好的對話框來選擇目錄 ,則需要一個Microsoft.WindowsAPICodePack
Nuget包:
using Microsoft.WindowsAPICodePack.Dialogs;
using System.IO;
// ....
var browserDialog = new CommonOpenFileDialog();
browserDialog.IsFolderPicker = true;
browserDialog.Title = Title;
// ---
您需要在項目中向PresentationFramework.dll添加引用
然后,您可以簡單地使用:
private Microsoft.Win32.SaveFileDialog saveDialog = new SaveFileDialog();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.