白色 - 文件打开对话框

8
这是我的问题。我有一个应用程序,在其中打开一个文件打开对话框,我正在尝试将文件路径和文件名输入到“文件名:”组合框部分中。
应用程序加载时会出现一个表单,您需要在其中登录。这将打开另一个具有多个按钮的表单。选择其中一个按钮会打开另一个表单。正是在这个表单中,有一个按钮用于选择文件。此时打开标准文件打开对话框。我似乎无法掌握此文件打开对话框。
以下是我使用的代码。
Window LoginForm = application.GetWindow("LoginForm");
LoginForm.Get<Button>("btnSelectFiles").Click(); // This is from the 3rd form that is opened 

由于某些原因,我可以使用LoginForm变量从其他表单访问所有按钮。 我尝试了以下方法。
Window FileOpenDialog = application.GetWindow("Open", InitializeOption.NoCache);

这个不起作用。

我还尝试了以下操作,但返回null。我以为我可以使用LoginForm变量来访问它。

Win32ComboBox comboBox = LoginForm.Get<Win32ComboBox>("Filename"); 

有什么想法吗?谢谢。
2个回答

7

打开文件对话框是一个模态窗口。您需要使用 LoginForm.ModalWindows() 函数。参考自 White 项目 Wiki

Window mainWindow = application.GetWindow("main");
List<Window> modalWindows = mainWindow.ModalWindows(); //list of all the modal windows belong to the window.
Window childWindow = mainWindow.ModalWindow("child"); //modal window with title "child"
childWindow.IsModal; //returns true

0
标准文件打开对话框。我似乎无法掌握这个文件打开对话框。 另一个解决方案只是...
Window FileOpenDialog = application.GetWindows().Last();

我经常使用它,因为当显示时(并且考虑到它是模态的),OpenFileDialog 是您在应用程序中打开的最后一个窗口;对于这个问题,我想不出更好的一行解决方案。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接