【问题标题】:VistaOpenFileDialog does not start with the correct initial directoryVistaOpenFileDialog 没有从正确的初始目录开始
【发布时间】:2016-03-28 15:00:10
【问题描述】:

参考:Ookii.Dialogs.Wpf.VistaOpenFileDialog

我正在尝试像这样设置 Ookii 的 VistaOpenFileDialog 初始目录:

    VistaOpenFileDialog vfb = new VistaOpenFileDialog();
        vfb.Multiselect = true;
        vfb.Title = "pouet";
        vfb.RestoreDirectory = false;
        vfb.InitialDirectory = @"C:\Users\";
        if (vfb.ShowDialog() ?? false)
        {
            this.Dispatcher.Invoke(DispatcherPriority.Send, new Action(delegate
            {
                for (var i = 0; i < vfb.FileNames.Length; i++)
                {
                    FileDisplay.Add(vfb.FileNames[i]);                    
                }
            }));
        }
    }

    private void AddFiles_Click(object sender, RoutedEventArgs e)
    {
        t = new Thread(new ThreadStart(AddFileDialog));
        t.SetApartmentState(ApartmentState.STA);
        t.Start();
    }

但是无论我尝试什么都行不通,对话框一开始就不会被初始目录打开,也永远不会被初始目录重新打开。我仍然可以毫无问题地选择文件夹中的文件。

我已经尝试了以下(作为测试):

vfb.InitialDirectory = @"C:\Users\";
vfb.InitialDirectory = "C:\\Users\\";
vfb.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop).ToString();

也试过 restoredirectory true 或 false 不会改变任何东西。

【问题讨论】:

    标签: c# dialog


    【解决方案1】:

    我也遇到了这个问题。我不知道为什么它不能那样工作,但我发现如果你改为将 FileName 属性设置为该文件夹,它将在指定路径打开:

    VistaOpenFileDialog dialog = new VistaOpenFileDialog();
    // To show the contents of "C:\", i.e. the parent of "Users":
    dialog.FileName = @"C:\Users"
    // To show the contents of the "Users" directory:
    dialog.FileName = @"C:\Users\"
    

    【讨论】:

      猜你喜欢
      • 2014-02-27
      • 2016-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-27
      • 2015-06-04
      相关资源
      最近更新 更多