Finding the TextBlock that is part of the default control template ComboBox generated through code.
Posted
by uriya
on Stack Overflow
See other posts from Stack Overflow
or by uriya
Published on 2010-04-29T11:13:13Z
Indexed on
2010/04/29
11:17 UTC
Read the original article
Hit count: 389
I'm trying to find the TextBlock that is inside the control template of a comboBox. using VisualTreeHelpar.GetChildrenCount is working only if the comboBox is declared in XAML.In that case GetChildrenCount returns 1 and a recursive search is possible.
However, if I declare the combo as a member of the Window class using code, allocated and setting it to its place, the function GetChildrenCount return 0. When I run snoop in this scenario It shows the combo children hierarchy. I want to be able to search the comboBox just as snoop does. Any help would be appreciated. code:
ComboBox mCombo = null;
private void Windows_Loaded(object sender, RoutedEventArgs e)
{
mCombo = new ComboBox;
mGrid.Children.Add(mCombo);
Grid.SetRow(mCombo,0);
int count = VisualTreeHelpar.GetChildrenCount(mCombo);
}
© Stack Overflow or respective owner