是否可以使用通配符在XAML(Silverlight)中找到控件?

时间:2012-01-13 23:35:35

标签: silverlight wildcard findcontrol

是否可以使用通配符在XAML(Silverlight)中找到控件?

Ex ..在我的XAML中

<TextBlock Text="Title" Grid.Row="0" Grid.Column="0" Style="{StaticResource txtBlock}" />
            <TextBox x:Name="uxTitle" Grid.Row="0" Grid.Column="1" IsReadOnly="{StaticResource IsControlReadOnly}"
                     Text="{Binding Title, Mode=TwoWay}" Style="{StaticResource txtBox}" Width="100"/>

            <TextBlock Text="Firstname" Grid.Row="1" Grid.Column="0" Style="{StaticResource txtBlock}" />
            <TextBox x:Name="uxFirstName" Grid.Row="1" Grid.Column="1" 
                     Text="{Binding FirstName, Mode=TwoWay}" Style="{StaticResource txtBox}" Width="250"/>

            <TextBlock Text="Middlename" Grid.Row="2" Grid.Column="0" Style="{StaticResource txtBlock}" />
            <TextBox x:Name="uxMiddleName" Grid.Row="2" Grid.Column="1" 
                     Text="{Binding MiddleName, Mode=TwoWay}" Style="{StaticResource txtBox}" Width="250"/>

在Codebehind中

public void searchControl()
{
      this.LayoutRoot.FindName("ux*");

      // Or like this way
      this.LayoutRoot.FindName("ux???");
}

1 个答案:

答案 0 :(得分:1)

在这里,您可以找到有用的解决方案“FindControl ID weirdness