I'm trying to access an AutoCompleteBox
on one of my screens. I can see that FindControl()
has located the control when I do var testControl = FindControl("MyControl");
However, when I attempt to cast this to the type of control it is supposed to be so I can manipulate it, the result is null
.
This is what I'm doing:
System.Windows.Controls.AutoCompleteBox testBox = new System.Windows.Controls.AutoCompleteBox();
testBox = testControl as System.Windows.Controls.AutoCompleteBox;
testBox
will be null.
It definitely says the control is an AutoCompleteBox
on the screen, I'm not sure what I'm doing wrong. Can anyone help?
EDIT: Thanks to Yann, I was able to resolve this with the following code:
this.FindControl("MyControl").ControlAvailable += (p, e) =>
{
//For every use I can just cast like ((System.Windows.Controls.AutoCompleteBox)e.Control)
};