zoukankan      html  css  js  c++  java
  • 在WPF里面如何使用FolderBrowserDialog

    System.Windows.Forms.FolderBrowserDialog fd = new System.Windows.Forms.FolderBrowserDialog();
    fd.ShowDialog(
    this);

    上面的代码如果是在WinForm程序里面,是没有问题的。但是如果在WPF里面则编译不通过,错误描述是

    The best overloaded method match for 'System.Windows.Forms.CommonDialog.ShowDialog(System.Windows.Forms.IWin32Window)' has some invalid arguments。

    这是因为WPF的窗口不是继承IWin32Window接口的,继承的是System.Windows.IWindowService接口。如果想在WPF程序里面使用FolderBrowserDialog,可以象下面这么写:

    private class OldWindow : System.Windows.Forms.IWin32Window
            
    {
                IntPtr _handle;
                
    public OldWindow(IntPtr handle)
                
    {
                    _handle 
    = handle;
                }


                
    IWin32Window Members
            }




    System.Windows.Forms.FolderBrowserDialog fd 
    = new System.Windows.Forms.FolderBrowserDialog();
    fd.ShowNewFolderButton 
    = false;
    System.Windows.Interop.HwndSource source 
    = PresentationSource.FromVisual(thisas System.Windows.Interop.HwndSource;
    System.Windows.Forms.IWin32Window win 
    = new OldWindow(source.Handle);
    fd.ShowDialog(
    this);
  • 相关阅读:
    vue中封装公共方法,全局使用
    element-ui table 最后一行合计,单元格合并
    vuex 进行封装
    vue生命周期
    (转)no terminal library found
    解压
    (转)bash: make: command not found
    (转)linux 批量删除文件命令
    python
    Session
  • 原文地址:https://www.cnblogs.com/pdfw/p/1422178.html
Copyright © 2011-2022 走看看