I need to focus XamMaskedEditor through Automation.
I have an XamMaskedEditor with AutomationID="xme1".
AutomationElement xme1 = library.GetElement(mainWindow, AutomationElement.AutomationIdProperty, "xme1", TreeScope.Descendants);xme1.SetFocus();While executing the second statement, an exception is thrown.The target element cannot receive focus. at MS.Internal.Automation.ElementUtil.Invoke(AutomationPeer peer, DispatcherOperationCallback work, Object arg)Call Stack:> UIAutomationClient.dll!MS.Internal.Automation.UiaCoreApi.CheckError(int hr) Line 1223 C# UIAutomationClient.dll!System.Windows.Automation.AutomationElement.SetFocus() Line 916 + 0x21 bytes C# CalculatorTest.exe!CalculatorTest.TestCalc.StartTest() Line 26 + 0xa bytes C# CalculatorTest.exe!CalculatorTest.Program.Main(string[] args) Line 14 + 0x1d bytes C#Please help me with this issue.
Hi,
Could you please tell us which version you are using(it seems like: 12.1.1010).
Looking for your reply.
Regards,
Anastas
We are using version 11.2. Please provide a workaround in 11.2 if this issue is fixed for 12.1 as we are not in a position to upgrade the existing project to 12.1. I haven't tested for 12.1.
It seems that this is a bug in our control.
For now you can use SetFocuc() method inside try catch block. Looking for your reply if this workaround works for you.
Using the try-catch block won't work for me since the code is raising the exception everytime I call SetFocus(). Please provide an alternate workaround.
Also, when I focus the element using XamMaskedEditor.Focus(), it doesn't raise any exception and behaves as expected. This certainly means that the element can receive focus. Can you please provide me any possible explanation for this?
I tried to look into the Template of this control using ExpressionBlend. We can certainly extract the TextBlock(Normal Template) or PART_InputTextBox(Edit Template) and try to set focus onto these controls. But, this will require code changes at a lot of places. Please specify any other workaround to get this done.
Another thing I forgot to mention is that we are using Visual Basic for Applications for Automation scripts. Can you please specify whether the workaround that I mentioned above can be used in VBA. If yes, please provide some sample code.