首页 新闻 会员 周边 捐助

silverlight里的FindName的问题

1
悬赏园豆:50 [已解决问题] 解决于 2011-12-06 10:36

xaml:

<Grid x:Name="LayoutRoot" Background="White">
<sdk:TabControl Height="100" HorizontalAlignment="Left" Margin="72,136,0,0" Name="tabControl1" VerticalAlignment="Top" Width="200">
<sdk:TabItem Header="tabItem1" Name="tabItem1">
<Grid />
</sdk:TabItem>
</sdk:TabControl>
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="118,44,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>

code behind:

public MainPage()
{
InitializeComponent();
TabItem ti
= new TabItem();
tabControl1.Items.Add(ti);
Grid g1
= new Grid();
g1.Name
= "g1";
ti.Content
= g1;
Grid g2
= new Grid();
g2.Name
= "g2";
g1.Children.Add(g2);
object o1 = FindName("g1");
object o2 = FindName("g2");
}

private void button1_Click(object sender, RoutedEventArgs e)
{
TabItem ti
= new TabItem();
tabControl1.Items.Add(ti);
Grid g3
= new Grid();
g3.Name
= "g3";
ti.Content
= g3;
Grid g4
= new Grid();
g4.Name
= "g4";
g3.Children.Add(g4);
object o1 = FindName("g3");
object o2 = FindName("g4");
}

最后一个g4始终找不到,不知为何,本人初学silverlight,很多不懂,希望高手们能不吝赐教 

松鼠鱼的主页 松鼠鱼 | 初学一级 | 园豆:185
提问于:2011-04-22 19:19
< >
分享
最佳答案
0

我来赐教啦~

把tabControl1.Items.Add(ti);
移动到g3.Children.Add(g4);
下面,原因还没研究

收获园豆:50
yissyo | 菜鸟二级 |园豆:255 | 2011-04-23 17:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册