How to use a FolderBrowserDialog from a WPF application

前端 未结 10 2085
青春惊慌失措
青春惊慌失措 2020-12-02 10:29

I\'m trying to use the FolderBrowserDialog from my WPF application - nothing fancy. I don\'t much care that it has the Windows Forms look to it.

However, when I call

10条回答
  •  鱼传尺愫
    2020-12-02 11:08

    //add a reference to System.Windows.Forms.dll
    
    public partial class MainWindow : Window, System.Windows.Forms.IWin32Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    
        private void button_Click(object sender, RoutedEventArgs e)
        {
            var fbd = new FolderBrowserDialog();
            fbd.ShowDialog(this);
        }
    
        IntPtr System.Windows.Forms.IWin32Window.Handle
        {
            get
            {
                return ((HwndSource)PresentationSource.FromVisual(this)).Handle;
            }
        }
    }
    

提交回复
热议问题