AutomationPeer - how to show data of elements not on the control? - automation

I want to write an AutomationPeer for my custom control in WPF.
Now, I want to show textBlocks \ TextBoxex that are not actually visible on my control.
I know how to override the method GetChildrenCore().
My problem is that when i run the playback (coded ui record) - it's trying to find a control not vissible on the window. Have you got any ideas?

You can set the SearchConfiguration VisibleOnly on the Coded UI control. Also, the UITestControl.FindMatchingControls method can let you know if the search properties are too ambiguous. Coded UI stops looking for a control after the first instance of a matching control is found.
inspect.exe can shed light on a form and how Coded UI may be seeing the control.
Try opening the Designer.cs and see the hierarchy and what Coded UI is trying to find.

Related

Manipulation events not triggering on Templated Control [UWP]

I am trying to implement a custom control (Templated Control) for a UWP application for transforming shapes (mostly Rectangle types). Custom control will be implemented in a UWP class library and reference to the main project. What I want to achieve is draw the custom control around another basic shape (eg: Rectangle) and transform the shape according to the manipulations done on the custom control.
I am trying to implement the control with manipulation events (ManipulationDelta, ManipulationCompleted).
I was able to achieve a similar behavior using pointer related events(PointerPressed, PointerMoved, PointerReleased) but it is not very smooth & I want to integrate this control with other applications easily.
Please find the sample source code here.
When I try to move the control the manipulation events are not firing, and I cannot figure out the reason.
I started to work on UWP applications recently and any help on this matter is highly appreciated.
In your scenario, there are several removing codes in PointPressed event, such as “RootCanvas.Children.Remove()”. When you move the control, the PointPressed event is triggered, the previous generated rectangle named resizableRectV2 is deleted. So the resizableRectV2.ManipulationCompleted event will not be triggered.
In addition, I suggest that you don’t create two completely overlapping rectangles, which makes you confused.
Update:
SpeakerView.xaml.cs:
RootCanvas.Children.Remove(RootCanvas.Children.Where(x => x.GetType() == typeof(ResizableRectangle)).FirstOrDefault());
I mean that you could delete the above code in OnPointerPressed event.

Add custom control to toolbox and have its properties show up in the properties window

To illustrate what I'm asking, let's say I have a custom TextBox that has 2 modes. Mode 1 only allows numbers, and mode 2 only allows dates in a particular format.
Using a class module I can create this custom TextBox, and I can use a loop when the userform initialises to set which TextBoxes are custom.
What I'd like to happen is have the custom TextBox, or what ever custom control I want, show up in the toolbox. And I also want its custom properties, if they exist, to show up in the property window.
So far, I've been unable to find a way to do this. In fact, I've been unable to find out if it's even possible. It seems, to me anyway, that it's something that should be possible, but maybe I'm barking up the wrong tree. If it's possible I'd really appreciate being pointed to a resource.

MFC Custom Keyboard DLL Accessed from Application Dialog Box

The overall goal is to be able to access a pop-up keyboard through an application that I am making in MFC.
I have created a dialog box with an empty text field. I would like to be able to click the empty field and have an onscreen keyboard to enter in the data field.
Is there list of functions or tutorials that anyone can provide me with to be able to perform this function? Ultimate I will be making the keyboard from scratch, so any guidance would be useful.
My first thoughts (I might be wrong someone might correct me if i am wrong.)
1)Create your Keyboard Ui in an MFC DLL and export the KeyBoard Functions like LaunchKB(Int screenx,int screeny) and CloseKB()
functions.
2)I would subClass CEdit and CRichedit such that when the edit control gains or loses focus it would call LaunchKB() function with windows ScreenX coordinates where the keyboard has to be displayed or CloseKB().
3) A callback function registered to dll ,which would get called for every click on the keyboard with characters clicked and these characters are to be displayed in the edit control.
This is just my thought ,there may be better ways to implement as well.

Exposing a Custom Control to Coded UI Tests - WinForms

I wrote my own custom control in WinForms. It's actually works like a TextBox, but have other methodes and extra properties that I wrote.
I tried writing a very simple coded UI test for this control but faild. Every Time I select it with the Coded UI Test Builder it is shown as "Client" and not as a textbox. I cannot read or write to the text property of this control, or get or set other properties.
Do you know how do I expose my custom control for testing, and getting and setting all of it properties?
It is difficult to answer the question without looking at your implementation of the custom control but you can use the following link to learn how to extend a treeview control to make it code UI enabled.
http://www.ranorex.com/blog/enabling-automation-by-adding-accessibility-to-windows-forms-controls
I used that example to learn how to extend my own controls.

CTRL+ TAB when webbrowser is in focus

I have a windows application with a tabcontrol. One of the tab of the tabcontrol has a webbrowser control.Now the issue that I am facing is when the focus is inside the webbrowser control, the normal Ctrl+Tab functionality of the tabcontrol is not working.I want the Ctrl+Tab to change the selected tab of tabcontrol even when the focus is inside webbrowser control in selected tab.How to achieve this ?
I have already tries overriding ProcessCmdKey.but it does not get hit when focus is inside webbrowser control.
I also tried registerhotkey method ,it works but it locks the Ctrl+Tab hotkey within my application & system doesn't respond to any other Ctrl+Tab presses outside my application when application is running, which is expected behaviour of registerhotkey.
Here is the code you need:
If WB.ContainsFocus Then
MsgBox("We have focus, disappearing...")
WB.Document.Body.RemoveFocus()
End If
Now, the question is, when to run that code. If you put it in the WebBrowser1_GotFocus event, you'll need to turn it on and off. Turn the code off if the user is interacting with the WB Control, and turn it back on when they are not and when you expect to be experiencing the problem you've mentioned.
Of course, you could add another line to ensure a particular control/tab/panel etc gets focus after you remove focus from the body. Also, here are 3 other SO questions that have answers which may help you, but these will take you in directions different to the direction I've provided, probably due to the fact that the questions are not identical to yours, but are similar enough to be useful (not listed in order of preference).
Prevent WebBrowser control from stealing focus?
Webbrowser steals focus
Focusing WebBrowser control in a C# application
UPDATE:
I just wanted to add, instead of the .Body.RemoveFocus() you could do this:
WB.Document.Body.Parent.RemoveFocus()
Which I prefer, since the .Document object didn't have an explicit .RemoveFocus method on the intellisense I was gettign in VS2012 RC. This is probably referring to the HTML tag (and not the .Document object) and since the html tag is the only parent to the body tag, it makes sense, and there is no "HTML" object directly available in the intellisense under object, since you can get it via other means, so it's just more convenient doing it this way.
Cheers, and let me know if you need more info on anything.