The Reason for this issue:
The control is placed inside an invisible control which is placed inside a parent control. As it is in your code, combLegal
combobox is inside the customContr
Wpfcontrol. but there is another control which blocks you accessing the combobox. The designers must have used this for some other purposes while debugging, and forgotten to remove it after they have done it.
The Possible solutions:
1. Try accessing the invisible control by its parent.
WpfControl customContr = new WpfControl(subDvnMap.SubDvsnItemCustom......);
customContr.SearchProperties.Add(....AutomationId, "legalFormatsControl");
foreach(WpfControl TempContr in customContr.GetChildren())
{
WpfControl ChildContr = TempContr.GetChildren().ElementAt(0);
if(ChildContr is WpfComboBox)
{
combLegal.SelectedIndex = 2;
break;
}
}
2. Try accessing control by checking its width.
WpfControl customContr = new WpfControl(subDvnMap.SubDvsnItemCustom......);
customContr.SearchProperties.Add(....AutomationId, "legalFormatsControl");
foreach(WpfControl TempContr in customContr.GetChildren())
{
if(TempContr.BoundingRectangle.Width>0)
{
combLegal.SelectedIndex = 2;
break;
}
}
3. Try accessing control by checking its Parent's width.
WpfControl customContr = new WpfControl(subDvnMap.SubDvsnItemCustom......);
customContr.SearchProperties.Add(....AutomationId, "legalFormatsControl");
foreach(WpfControl TempContr in customContr.GetChildren())
{
if(TempContr.BoundingRectangle.Width>0)
{
WpfControlCollection Collection = TempContr.GetChildren();
foreach(WpfControl combLegal in Collection)
{
if(combLegal is WpfComboBox)
{
combLegal.SelectedIndex = 2;
break;
}
}
}
}
One of these should resolve your issue. If not, do comment below, we shall give some more attempts. good luck..!!