Ok, I see what you mean. I was merely looking for a way to do this with a UserControl... I guess nobody has done this (nor wanted it :)).
I have added a Class to my test project:
1 namespace SilverlightApplication3
2 {
3 public class MyPanel : StackPanel
4 {
5 public MyPanel()
6 {
7 this.Loaded += new RoutedEventHandler(MyPanel_Loaded);
8 }
9
10 void MyPanel_Loaded(object sender, RoutedEventArgs e)
11 {
12 double totalHeight = 0;
13 foreach (UIElement element in this.Children)
14 {
15 if (element.GetType() == typeof(Button))
16 {
17 ((Button)element).UpdateLayout();
18 totalHeight += ((Button)element).ActualHeight;
19 }
20 }
21 this.Height = totalHeight;
22 }
23 }
24 }
And now the Page.Xaml looks like:
<UserControl x:Class="SilverlightApplication3.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:custom="clr-namespace:SilverlightApplication3"
Width="400" Height="300">
<StackPanel Orientation="Vertical" x:Name="LayoutRoot" Background="Yellow">
<custom:MyPanel x:Name="test" Width="Auto" Height="100" VerticalAlignment="Top">
<custom:MyPanel.Children>
<Button Content="Test" x:Name="button1"></Button>
</custom:MyPanel.Children>
</custom:MyPanel>
<Button Content="Extra"></Button>
</StackPanel>
</UserControl>
And this seems to be working.
Now I can check in the page loaded event which children are available.
Thanks for your help.
Regards,
Marrik
Live long and prosper!