我的小FolderBrowserDialog实现不起作用

时间:2016-10-20 13:50:32

标签: wpf openfiledialog folderbrowserdialog

我知道有很多可用的WPF FolderBrowserDialog实现。 但我的想法是为OpenFileDialog编写一个外观并设置FOS_PICKFOLDERS标志,而不是编写一个完整的新实现。

但它不起作用。

public sealed class FolderDialog 
{
    private OpenFileDialog dlg;

    public FolderDialog()
    {
        this.dlg = new OpenFileDialog();
        SetOption(0x00000020, true);    // FOS_PICKFOLDERS  
        bool b = GetOption(0x00000020);
    }

    private bool GetOption(int option)
    {
        return (bool)typeof(FileDialog).InvokeMember("GetOption", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, null, this.dlg, new object[] { option });
    }

    private void SetOption(int option, bool value)
    {
        typeof(FileDialog).InvokeMember("SetOption", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, null, this.dlg, new object[] { option, value });
    }

    public string Title
    {
        get { return this.dlg.Title; }
        set { this.dlg.Title = value; }
    }

    public string FileName 
    {
        get { return this.dlg.FileName; }
    }

    public bool? ShowDialog()
    {
        return this.dlg.ShowDialog();
    }

    public bool? ShowDialog(Window owner)
    {
        return this.dlg.ShowDialog(owner);
    }
}

0 个答案:

没有答案