获得特定的UIElemet从网格在Windows Phone与可视化树的帮助

本文关键字:Windows Phone 可视化 帮助 网格 UIElemet | 更新日期: 2023-09-27 18:13:25

我在windows phone xaml页面中有网格视图,这个网格包含许多UI元素,如按钮,复选框和文本框。我想根据名称从网格中搜索特定的uielelement并获取该uielelement的值并设置一些新值。我如何从网格中获得与Visual Tree helper在代码后面的元素。

<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>

我想匹配选项。让我们说左边一些图片被点击,它的边界改变了,一旦在右边点击哪个选项是匹配的,左边有一些选择或没有

获得特定的UIElemet从网格在Windows Phone与可视化树的帮助

你能告诉我你到底想从网格元素中得到什么,因为里面只有边框和图像。您可以通过这个泛型编码找到元素。(ContentPanel是你的网格名称),你可以得到边界和图像和其他控件的名称和其他属性,以及下面的程序。

 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;
                }
            }
        }

如果这对你有帮助,那么很好,否则解释你的任务多一点,然后我将发送给你确切的代码InshaAllah