File system browser window

This section demonstrates the use of the file system browser window:

MainWindow.xaml

A button is placed in a window with an attached click event handler which instantiates a file system browser window.

<Window Title="Example Project" x:Class="ExampleProject.MainWindow" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <WrapPanel Margin="10">
        <Button Click="FileSystemBrowserWindowButton_Click" Content="FileSystemBrowserWindow" Padding="15, 2"/>
    </WrapPanel>
</Window>

MainWindow.xaml.cs

A file system browser window is instantiated and the main window is made its owner before it is displayed:

namespace ExampleProject
{
    using System.Windows;
    using Emi.UserControls;

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
        }

        private void FileSystemBrowserWindowButton_Click(object sender, RoutedEventArgs e)
        {
            // The constructor can take a BrowserSettings instance.
            FileSystemBrowserWindow exampleFileSystemBrowserWindow = new FileSystemBrowserWindow();

            // The file system browser window should be owned by the window instantiating it.
            exampleFileSystemBrowserWindow.Owner = this;

            // Display the window with the ShowDialog method and wait for it to return directories and/or files.
            if (exampleFileSystemBrowserWindow.ShowDialog() ?? true)
            {
                foreach (string directory in exampleFileSystemBrowserWindow.SelectedDirectories)
                {
                    // Do something with the selected directories.
                }

                foreach (string file in exampleFileSystemBrowserWindow.SelectedFiles)
                {
                    // Do something with the selected files.
                }
            }
        }
    }
}

Gallery

A demonstration of the file system browser window file selection. A demonstration of the file system browser window file saving. A demonstration of the file system browser window file saving with encoding.