Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to WPF.I want to show different images from drive and show it in grid with 2 rows and 3 columns with paging.
I am able to display images in single column using below code
C#
XMAL :
<DatGrid>
<DataGrid.Columns   >
                <DataGridTemplateColumn Header="SampleImages">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Height="70" Width="70" Source="{Binding}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                 
                </DataGridTemplateColumn>  
            </DataGrid.Columns></DatGrid>


XMAL.CS

string path = Environment.CurrentDirectory+ "\\snapshot\\";
List<string> imageList = new List<string>();
string[] images = System.IO.Directory.GetFiles(path);
Image image= new Image();
foreach (string Img in images)
{
BitmapImage bmp = new BitmapImage();

bmp.BeginInit();
bmp.UriSource = new Uri(Img, UriKind.Relative);
bmp.EndInit();

image.Source = bmp;
//imageList.Add(new Image { Source = bmp });
imageList.Add(Img);
}

imageDataGrid.ItemsSource = imageList;

Please note these images are generated run time and stored on specified path in code.
But not able to display in 2 rows and 3 columns with pagination.I also want to use MVVM.
Searched alot but not able to get any fruitful results.Can anybody guide me in the same.

Thanks in advance.
Posted
Updated 30-Jan-14 19:35pm
v2

1 solution

XML
<grid>

<rowdefinitions>
<rowdefinition height="Auto" />
<rowdefinition height="Auto" />
</rowdefinitions>
<columndefinitions>
<columndefinition width="Auto" />
<columndefinition width="Auto" /><code></code>
<columndefinition width="Auto" />
</columndefinitions>

<image source="{Binding}" grid.row="0" grid.column="1" />
<image source="{Binding}" grid.row="0" grid.column="2" />
<image source="{Binding}" grid.row="0" grid.column="3" />
<image source="{Binding}" grid.row="1" grid.column="1" />
<image source="{Binding}" grid.row="1" grid.column="2" />
<image source="{Binding}" grid.row="1" grid.column="3" />

</grid>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900