0

I have grid view in windows phone xaml page and this grid contains many UI element like buttons, checkboxes and textboxes. I want to search some specific UIElement by name from that grid and want to get value of that UIElement and set some new values as well. How I can get that UIElement from that grid with Visual Tree helper in code behind.

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="120" />
                <RowDefinition Height="120" />
                <RowDefinition Height="120" />
                <RowDefinition Height="120" />
                <RowDefinition Height="120" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="240" />
                <ColumnDefinition Width="240" />
            </Grid.ColumnDefinitions>
            <Border BorderThickness="2" HorizontalAlignment="Left" Grid.Row="0" Grid.Column="0" Name="Border1">
                <Image Width="110" Height="110" Stretch="Fill" Name="Image1" Tap="Image1_Tap" />
            </Border>
            <Border BorderThickness="2" BorderBrush="Transparent" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="0" Name="Border2">
                <Image Width="110" Height="110" Stretch="Fill" Name="Image2" Tap="Image2_Tap" />
            </Border>
            <Border BorderThickness="2" HorizontalAlignment="Left" Grid.Row="2" Grid.Column="0" Name="Border3">
                <Image Width="110" Height="110" Stretch="Fill" Name="Image3" Tap="Image3_Tap" />
            </Border>
            <Border BorderThickness="2" HorizontalAlignment="Left" Grid.Row="3" Grid.Column="0" Name="Border4">
                <Image Width="110" Height="110" Stretch="Fill" Name="Image4" Tap="Image4_Tap" />
            </Border>
            <Border BorderThickness="2" HorizontalAlignment="Left" Grid.Row="5" Grid.Column="0" Name="Border5">
                <Image Width="110" Height="110" Stretch="Fill" Name="Image5" Tap="Image5_Tap" />
            </Border>
            <Border BorderThickness="2" HorizontalAlignment="Right" Grid.Row="0" Grid.Column="1" Name="Border11">
                <Image Width="110" Height="110" Stretch="Fill" Name="Image11" Tap="Image11_Tap" />
            </Border>
            <Border BorderThickness="2" HorizontalAlignment="Right" Grid.Row="1" Grid.Column="1" Name="Border22">
                <Image Width="110" Height="110" Stretch="Fill" Name="Image22" Tap="Image22_Tap" />
            </Border>
            <Border BorderThickness="2" HorizontalAlignment="Right" Grid.Row="2" Grid.Column="1" Name="Border33">
                <Image Width="110" Height="110" Stretch="Fill" Name="Image33" Tap="Image33_Tap" />
            </Border>
            <Border BorderThickness="2" HorizontalAlignment="Right" Grid.Row="3" Grid.Column="1" Name="Border44">
                <Image Width="110" Height="110" Stretch="Fill" Name="Image44" Tap="Image44_Tap" />
            </Border>
            <Border BorderThickness="2" HorizontalAlignment="Right" Grid.Row="5" Grid.Column="1" Name="Border55">
                <Image Width="110" Height="110" Stretch="Fill" Name="Image55" Tap="Image55_Tap" />
            </Border>
        </Grid>

I want to match options. Lets Say Left Side Some Images Are Clicked And Its Border Changed And Once On Right SIde Clicked Which Option is Matched Either Left SIde Have Some Selection or Not

Arslan Pervaiz
  • 1,575
  • 4
  • 29
  • 62

1 Answers1

1

Can you tell me what exactly you want to get from the grid elements, because there are only Borders and Images inside. You can find elements via this generic coding. (ContentPanel is your grid name), You can get the Border and Image and other controls name and other properties as well on the following procedure.

 foreach (var child in ContentPanel.Children)
        {
            if (child is Border)
            {
                var borderName = (child as Border).Name;

                // if you wana get the image inside border, then do this.
                var getBorderChlid = (item as Border).Child;
                if (getBorderChlid is Image)
                {
                    var getImgName = (getBorderChlid as Image).Name;
                }

            }
        }

If this help you then well and good, otherwise explain your quest a bit more, then I will send you the exact code InshaAllah.

Zia Ur Rahman
  • 1,850
  • 1
  • 21
  • 30