[WPF] Only elements in the ItemsPresenter can be found for the control that derived from subclass of Selector.
In WPF, for those custom controls derived from subclass of Selector, (e.g.: ListBox, TabControl, ComboBox, DataGrid etc.) only elements within the ItemsPresenter can be found by inspect.exe.
I have written a minimal demo, please see attachment.
In this Demo, I created a custom control (CustomControl.cs), which derived from ListBox, and you can also change it to TabControl, ComboBox and DataGrid etc. The custom control has a custom dependency property named CustomRegion, and I added a ControlTemplate for the custom control. see below for details:

Then, I used the CustomControl in MainWindow.xaml, as shown below:

Run this Demo:

Now, we can open inspect.exe to inspect the Window instance. I tried to change the base class of the CustomControl and the result is as follows:

We can see that those elements contained by CustomRegion CANNOT be inspected by inspect.exe. It seems that the inspect.exe tool seems to treat these controls as IEnumerable, and just simply iterates over it, and ignoring all other elements.
BUT, if the CustomControl directly derived from Selector, the result as shown below:

- I wonder why
inspect.execan't inspect them? - What should I do if I need to test these elements?
Thanks!
Attachment
Demo: WpfApp.TestWAD.zip
Try adding following override method OnCreateAutomationPeer in your CustomControl class and see if it works for you:
protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
{
return new System.Windows.Automation.Peers.FrameworkElementAutomationPeer(this);
}