I am new to WindowsApp Development and I was trying to access XAML elements through C# code using an array.
For example I have few ellipses in my XAML code-
<Ellipse Fill="#FFF4F4F5" x:Name="E_0" Grid.Row="0" Grid.Column="2" Stroke="Black" RenderTransformOrigin="0.474,5.849" Visibility="Visible" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Ellipse Fill="#FFF4F4F5" x:Name="E_1" Grid.Row="0" Grid.Column="3" Stroke="Black" RenderTransformOrigin="0.474,5.849" Visibility="Visible" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Ellipse Fill="#FFF4F4F5" x:Name="E_2" Grid.Row="0" Grid.Column="4" Stroke="Black" RenderTransformOrigin="0.474,5.849" Visibility="Visible" HorizontalAlignment="Center" VerticalAlignment="Center"/>
Now I want to work with them in C# in a loop so I am doing something similar to the following-
string s1="E_";
double width=500;
for (int i = 0; i < 2;i++ )
{
string name_i = s1 + i.ToString();
name_i.Width = width / 2;
}
But name_i.width gives me an error. So, do I have to use the actual names, is there no way I can use an array or string? Using the actual names will defeat the purpose as I have about 50 such elements which I need to work upon.
Ellipseobjects in a container and give that container a variable name, couldn't you loop through theChildrenof that container and affect every eclipse thereby?Ellipsesin a Grid by the name ofGame. But if I enumerate the children, how can I check only for theEllipseelements and not other elements present in thatGrid?Childrenand the inner loop iterating over myvar ellipses. Is there some way, I can do this using a single array instead ofContainerbecause if it is possible, the n I think it would be more efficient.Children, or you group them in an array by code with theEllipse[] ellipses = { ... };and iterate over this array, but not both at once.new Ellipse[]before the{but I think that has become redundant with newer C# versions.