First and foremost, I apologize for my grammatical errors; my first language is Persian (Iran).
I have 30 images (*.png) that i want to display randomly in 30 Image Control.
I wrote the following codes but ...
XAML codes
<GroupBox x:Name="ImageGroupBox" Header="Image Recognition" Margin="10,38,0,0" HorizontalAlignment="Left" Height="423" VerticalAlignment="Top" Width="335">
<ItemsControl x:Name="ImageItemsControl" Margin="-6,-16,0,0" Height="423" Width="335" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid x:Name="ImageGrid" Margin="0,0" Height="423">
<Image x:Name="Image0" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="13.5,35,0,0"/>
<Image x:Name="Image1" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="75.5,35,0,0"/>
<Image x:Name="Image2" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="137.5,35,0,0"/>
<Image x:Name="Image3" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="199.5,35,0,0"/>
<Image x:Name="Image4" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="261.5,35,0,0"/>
<Image x:Name="Image5" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="13.5,97,0,0"/>
<Image x:Name="Image6" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="75.5,97,0,0"/>
<Image x:Name="Image7" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="137.5,97,0,0"/>
<Image x:Name="Image8" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="199.5,97,0,0"/>
<Image x:Name="Image9" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="261.5,97,0,0"/>
<Image x:Name="Image10" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="13.5,159,0,0"/>
<Image x:Name="Image11" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="75.5,159,0,0"/>
<Image x:Name="Image12" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="137.5,159,0,0"/>
<Image x:Name="Image13" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="199.5,159,0,0"/>
<Image x:Name="Image14" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="261.5,159,0,0"/>
<Image x:Name="Image15" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="13.5,221,0,0"/>
<Image x:Name="Image16" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="75.5,221,0,0"/>
<Image x:Name="Image17" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="137.5,221,0,0"/>
<Image x:Name="Image18" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="199.5,221,0,0"/>
<Image x:Name="Image19" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="261.5,221,0,0"/>
<Image x:Name="Image20" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="13.5,283,0,0"/>
<Image x:Name="Image21" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="75.5,283,0,0"/>
<Image x:Name="Image22" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="137.5,283,0,0"/>
<Image x:Name="Image23" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="199.5,283,0,0"/>
<Image x:Name="Image24" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="261.5,283,0,0"/>
<Image x:Name="Image25" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="13.5,345,0,0"/>
<Image x:Name="Image26" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="75.5,345,0,0"/>
<Image x:Name="Image27" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="137.5,345,0,0"/>
<Image x:Name="Image28" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="199.5,345,0,0"/>
<Image x:Name="Image29" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="60" Margin="261.5,345,0,0"/>
</Grid>
</ItemsControl>
</GroupBox>
C# Codes
//"Images" folder is in Solution Explorer
![102579-images.png][1]
DirectoryInfo DirInfo = new DirectoryInfo(@"Images/");
FileInfo[] FileInfo = DirInfo.GetFiles();
object[] ImagesList = FileInfo;
for (int i = 0; i < 30; i++)
{
//Name of Control + Number
var img = FindName("Image" + i.ToString()) as Image;
img.Source = (BitmapImage)ImagesList[i];
}
Thanks