我有白色的FolderBrowserDialog获取问题。我认为应该将其分配为模式窗口,但不是。

DialogService.cs中的FolderBrowserDialog:

 public FolderBrowserResult ShowFolderbrowserDialog(string storageFolder)
    {
        var dialog = new FolderBrowserDialog
        {
            Description = storageFolder
        };

        var result = new FolderBrowserResult
        {
            Result = dialog.ShowDialog() != DialogResult.OK,
            Path = dialog.SelectedPath
        };

        return result;
    }


单击浏览按钮后调用的方法:

private void OnBrowseForTargetFolder(object sender, RoutedEventArgs e)
    {
        var result = dialogService.ShowFolderbrowserDialog(Properties.Resources.StorageFolder);
        if (result.Result) return;

        Project.PathToStorage = result.Path;
        completePath = string.Format("{0}\\{1}", result.Path, Guid.NewGuid());
        Directory.CreateDirectory(completePath);
    }


测试:

public class LoggerTests
{
    private Application application;

    private MainWindowPage mainWindowPage;

    [TestInitialize]
    public void TestInitialize()
    {
        application = Application.Launch(@"PML.exe");
        StartBlankApplication();
    }

    [TestMethod]
    public void StartExistingProject()
    {
        mainWindowPage.StartExistingProjectButton.Click();
        var modalWindows = new List<Window>();
        Retry.For(() =>
        {
            modalWindows = mainWindowPage.applicationWindow.ModalWindows();
        }, TimeSpan.FromSeconds(5));

        var mod = modalWindows;
    }

    private MainWindowPage StartBlankApplication()
    {
        var appWindow = application.GetWindow("PML");
        mainWindowPage = new MainWindowPage(appWindow);
        return mainWindowPage;
    }

    private NewProjectConfigurationPage ConfigureBlankProject()
    {
        Window secondAppWindow = null;
        Retry.For(() =>
        {
            secondAppWindow = application.GetWindow("PML");
        }, TimeSpan.FromSeconds(5));

        var newProjectConfiguration = new NewProjectConfigurationPage(secondAppWindow);

        newProjectConfiguration.VesselName.Text = "Test";
        newProjectConfiguration.BrowseButton.Click();

        return newProjectConfiguration;
    }
}


在StartExistingProject方法中存在变量mod为空的问题。并且没有打开FolderBrowserDialog。但是当我正常运行应用程序时,一切运行正常。

最佳答案

已解决-必须将所有者设置为模式对话框。所以

 var wrapper = new WindowWrapper(this);

 dialog.ShowDialog(wrapper)


解决了我的问题。

08-19 17:22