I have a usercontrol with a dependencyproperty that takes oen UIElement. So fare so good, the problem is I can not find the element's children.
I think the problem is my lack of knowledge, could anyone tell me what the problem is and a possible solution?
I have made a small test-program like this
Usercontrol codebehinde:
public UIElement TestSendUiElement
{
get { return (StackPanel)GetValue(TestSendUiElementProperty); }
set { SetValue(TestSendUiElementProperty, value); }
}
public static readonly DependencyProperty TestSendUiElementProperty =
DependencyProperty.Register("TestSendUiElement", typeof(StackPanel), typeof(Test), new FrameworkPropertyMetadata(TestSendUiElementPropertyChanged));
private static void TestSendUiElementPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
{
Console.WriteLine(VisualTreeHelper.GetChildrenCount((UIElement)e.NewValue));
}
xaml using the usercontrol:
<my:Test >
<my:Test.TestSendUiElement>
<StackPanel Orientation="Horizontal" Margin="0,2">
<TextBox Height="23" Width="50" Margin="0,0,5,0" />
<TextBox Height="23" Width="125" />
</StackPanel>
</my:Test.TestSendUiElement>
</my:Test>
Output is 0 children.
Shouldn't it be 2?
Pleas enlighten me.