- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我们在 WPF 应用程序
的 WebBrowser 控件
中托管 MS-Word
文档。
WebBrowser 控件
在导航到选定的 MS-Word 文档期间显示以下对话:
我们尝试使用 AutomationElement
以编程方式关闭对话。该代码在测试应用程序中没有任何问题。当我们在实际应用程序中调整代码时(编辑
文件,使用mail merge
显示文件),只有mail merge
部分关闭对话正确。在另一种情况下,找不到对话的 AutomationElement。
我们发现当对话的 AutomationElement 有 IsWindowPatternAvailable = false
时我们的代码失败。
有没有办法提前设置这个属性?或者为什么它在一种情况下为真而在另一种情况下为假的原因?
测试应用程序是一个“标准 WPF 应用程序”项目。它只包含 MainWindow.xaml.cs 和 MainWindow.xaml。单击按钮设置 WebBrowser
的 Source
:
private void Button_Click(object sender, RoutedEventArgs e)
{
Thread thread = new Thread(new ThreadStart(backgroundCheck));
thread.Start();
this.TestBrowser.Source = new Uri(@"path-to-document.doc");
thread.Abort();
}
backgroundCheck
搜索特定对话并调用Open
按钮
private void backgroundCheck()
{
Thread.Sleep(500);
while (true)
{
AutomationElement window = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window));
if (window!= null)
{
AutomationElement downloadWindow = window.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window));
if (downloadWindow != null)
{
AutomationElement button = downloadWindow.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "4426"));
button.SetFocus();
(InvokePattern)button.GetCurrentPattern(InvokePattern.Pattern)).Invoke();
return;
}
}
}
}
我们的实际应用程序有点复杂,使用了 MVVM
、PRISM 5
和 WCF
。我们使用 WCF 从服务器加载 Word 文档。文件保存在 %temp%。
两个 ViewModel
(编辑文档/显示合并文档,每个都在一个不同的模块
中)发布一个事件
,查看
订阅:
public class VmExample
{
public delegate void BrowserNavigationEventHandler(string pfad);
public event BrowserNavigationEventHandler browserNavigate;
private void navigateToDocument()
{
browserNavigate("Path-To-Document.doc");
}
}
public partial class ViewMerge : UserControl
{
private VmExample _vm;
public ViewMerge()
{
InitializeComponent();
this.DataContextChanged += ViewMerge_DataContextChanged;
}
private void ViewMerge_DataContextChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
{
this._vm = e.NewValue as VmExample;
this._vm.browserNavigate += ViewMerge_browserNavigate;
this.DataContextChanged -= ViewMerge_DataContextChanged;
}
private void ViewMerge_browserNavigate(string path)
{
Thread threadCheckDownoadWindow = new Thread(backgroundCheck);
threadCheckDownoadWindow.Start();
this.wbBrowser.Source = new Uri(path);
threadCheckDownoadWindow.Abort();
this._vm.browserNavigate -= ViewMerge_browserNavigate;
}
}
我们在 inspect.exe
的帮助下发现了 IsWindowPatternAvailable
的不同之处。当 IsWindowPatternAvailable = true
时,对话是 Desktop
的直接子项并且可以找到。当 IsWindowPatternAvailable = false
时,我们在 inspect.exe
的 TreeView
中看不到对话,但我们可以通过单击访问对话的属性它。在 inspect.exe
中,我们看到以下 ancestors
:
当我们使用代码在“合并”模块中编辑文档时,对话正确关闭。两个模块引用相同的 UIAutomation
DLL(UIAutomationClient、UIAutomationProvider)。
这里提到了类似的问题:AutomationElement shows up using Inspect.exe but does show not up ...使用 TreeWalker
或搜索 AutomationElement.RootElement
的完整 Subtree
不起作用。
欢迎提供有关 IsWindowPatternAvailable
行为方式的任何线索。也欢迎提供有关如何关闭“文件下载”对话框的其他建议。
最佳答案
终于在这个 blog 的帮助下找到了解决我的问题的方法使用 UIAutomationEvents。
AutomationEventHandler UIAEventHandler = new AutomationEventHandler(OnUIAEvent);
Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent,
AutomationElement.RootElement,
TreeScope.Descendants, UIAEventHandler);
private static void OnUIAEvent(object src, AutomationEventArgs e)
{
AutomationElement element = src as AutomationElement;
if (element == null)
{
return;
}
AutomationElement openButton = element.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "4426"));
if (openButton != null)
{
openButton.SetFocus();
((InvokePattern)openButton.GetCurrentPattern(InvokePattern.Pattern)).Invoke();
}
}
关于c# - 在浏览器中托管 Word - AutomationElement IsWindowPatternAvailable - 如何设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38612550/
我想标记一个字符串,例如 Best Beat Makers,以几乎类似于 NGram 的方式为每个单词生成标记,例如: IN: "Best Beat Makers" OUT: ["Best", "B
这个问题在这里已经有了答案: Is there a way to word-wrap long words in a div? (6 个答案) 关闭 7 年前。
我想编写一个 Python 代码来检查字符串是否包含类似于以下内容的内容: 'word.Word' => 将其替换为 'word.\nWord'。 smallLetter.capitalLetter
我想编写一个 Python 代码来检查字符串是否包含类似于以下内容的内容: 'word.Word' => 将其替换为 'word.\nWord'。 smallLetter.capitalLetter
我有以下正则表达式: ^--([\w|-]+) 我想匹配 --word --no-word 但不是: ---word ----word 最佳答案 将表情更改为 ^--(\w[-\w]*) 这需要在两个
在我的加载项中,我需要为每个打开的文档创建一个任务 Pane 。在加载项的启动方法中,我订阅了 ApplicationEvents4_Event.NewDocument 和 Application.D
我使用 word javascript api 开发了一个 word 插件。我的文档 .docx 文件在服务器上,我需要在加载项中单击按钮打开该 .docx 文档作为新的 Word 文档。 请指导我如
我需要在某个地方修复一些 CSS,因为我的文本没有环绕,如果它是一个非常长的单词,它会无限期地继续下去。 在大多数情况下,我在我的 CSS 文件中尝试了 word-wrap: break-word;
这个问题在这里已经有了答案: What is the difference between "word-break: break-all" versus "word-wrap: break-word
这个问题在这里已经有了答案: What is the differect between word-wrap and overflow-wrap? [duplicate] (1 个回答) Is t
问题详细描述如下: 给定两个单词(beginWord 和 endWord)和字典的单词列表,找出是否存在从 beginWord 到 endWord 的转换序列,这样: 一次只能更改一个字母 每个转换后
我以前没有使用过邮件合并字段,我发现的所有内容都要求您在能够插入合并字段之前选择一个数据源。我想要做的就是将字段放在 word 文档上,并且在代码使用它之前不要将其合并。我基本上是在创建文档模板。这在
将此代码放置在ThisDocument_Startup之外的Word文档级VSTO解决方案中的某个位置(创建带单击事件的功能区按钮): int zero = 0; int divideByZero =
有没有办法在没有加载项的情况下启动 MS Word(仅此实例)?我只能找到一种方法来完全禁用加载项。 最佳答案 来自Word command line switches documentation ,
有没有办法在没有加载项的情况下启动 MS Word(仅此实例)?我只找到一种方法来完全禁用加载项。 最佳答案 来自Word command line switches documentation ,您
当使用 URI 方案从网页上托管的 word 模板打开新文档时不起作用。 https://msdn.microsoft.com/en-us/library/office/dn906146.aspx 这
我的问题: overflow-wrap: break-word 和 word-break: break-word 有区别吗? 非重复: 这里有一些现有的问题,乍一看可能是重复的,但实际上不是。 Wha
我希望使用 WordNet 从一组基本术语中寻找相似术语的集合。 例如,单词'discouraged' - 潜在的同义词可能是:daunted, glum, deterred, pessimistic
部署 Word Add in 时,发布没有错误。复制文件后出现以下错误。 我没有太多事情要做。这是堆栈跟踪。 ************** Exception Text **************
我需要一个 Java 正则表达式来匹配除某个单词之外的任何单词,同时包含另一个单词。 例如字符串中不能包含Apple,但必须有Peach。 Apple and Peach - Not match Pe
我是一名优秀的程序员,十分优秀!