Skip to content

Folder browser dialog

Mattias Kindborg edited this page May 19, 2016 · 2 revisions

To show a folder browser dialog start by registering the view by decorating the XAML with the attached property DialogServiceViews.IsRegistered.

<UserControl
    x:Class="DemoApplication.Features.FolderBrowserDialog.Views.FolderBrowserTabContent"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:md="https://github.com/fantasticfiasco/mvvm-dialogs"
    md:DialogServiceViews.IsRegistered="True">
  
</UserControl>

In the view model, open the dialog by calling IDialogService.ShowFolderBrowserDialog.

public class FolderBrowserTabContentViewModel : INotifyPropertyChanged
{
    private readonly IDialogService dialogService;
  
    public FolderBrowserTabContentViewModel(IDialogService dialogService)
    {
        this.dialogService = dialogService;
    }
  
    private void BrowseFolder()
    {
        var settings = new FolderBrowserDialogSettings
        {
            Description = "This is a description"
        };

        bool? success = dialogService.ShowFolderBrowserDialog(this, settings);
        if (success == true)
        {
            Path = settings.SelectedPath;
        }
    }
}