gpt4 book ai didi

c# - 小白测试——文件夹浏览器对话框

转载 作者:行者123 更新时间:2023-11-28 20:40:42 24 4
gpt4 key购买 nike

我在获取白色的 FolderBrowserDialog 时遇到问题。我认为它应该被指定为模态窗口,但事实并非如此。

DialogService.cs 中的文件夹浏览器对话框:

 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)

解决了我的问题。

关于c# - 小白测试——文件夹浏览器对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34217825/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com