I have a number (16 so far) of instances of user controls that I have built. Every one ot them have similar Properties. To each I gave a name: x:Name = "probeX" (where X is an int number). Each of these controls represent an electric probe.
I want to write a method that can access the user control by passed int value, to one of his properties.
For example: If the methods signature is: void SetMeasuredValueToProbe(int probe_number, int value ) then passing SetMeasuredValueToProbe(3, 22);
will sets "probe3" specific property to value 22.
I know that I can just make long switch case inside a method. But in the future I would like to exponentialy increace the number of the probes. So I would like to know what is the correct way to name and access an array of user controls.
XAML:
<StackPanel
Grid.Column="0">
<uc:ProbeTestControl x:Name="probe1" x:Uid="1" ProbeValue ="1"/>
<uc:ProbeTestControl x:Name="probe2" ProbeValue ="2"/>
<uc:ProbeTestControl x:Name="probe3" ProbeValue ="3"/>
<uc:ProbeTestControl x:Name="probe4" ProbeValue ="4"/>
<uc:ProbeTestControl x:Name="probe5" ProbeValue ="5"/>
<uc:ProbeTestControl x:Name="probe6" ProbeValue ="6"/>
<uc:ProbeTestControl x:Name="probe7" ProbeValue ="7"/>
<uc:ProbeTestControl x:Name="probe8" ProbeValue ="8"/>
</StackPanel>
<StackPanel
Grid.Column="1">
<uc:ProbeTestControl x:Name="probe9" ProbeValue ="9"/>
<uc:ProbeTestControl x:Name="probe10" ProbeValue ="10"/>
<uc:ProbeTestControl x:Name="probe11" ProbeValue ="11"/>
<uc:ProbeTestControl x:Name="probe12" ProbeValue ="12"/>
<uc:ProbeTestControl x:Name="probe13" ProbeValue ="13"/>
<uc:ProbeTestControl x:Name="probe14" ProbeValue ="14"/>
<uc:ProbeTestControl x:Name="probe15" ProbeValue ="15"/>
<uc:ProbeTestControl x:Name="probe16" ProbeValue ="16"/>
</StackPanel>
method in a MainWindow Class:
private void SetMeasuredValueToProbe(int probe_number, int value )
{
switch (probe_number)
{
case 1:
probe1.MeasuredValueBox = value;
break;
case 2:
probe2.MeasuredValueBox = value;
break;
default:
break;
}
}
I want to know the elegant way to do so, without making a spaghetti code.