Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Image Gallery: UserControl in table style Grid
8 replies. Latest Post by ehcarleton on November 7, 2009.
(0)
ehcarleton
Member
9 points
44 Posts
10-29-2009 10:51 PM |
I need to implement a paged table view of images for an image gallery. As an example, there might be 100 images and each page might show 20 images (5x4 table), in such a case there will be 5 different pages of images. In reality the number of rows and columns will be dictated by the image size and screen size.
Requirements:
I have played with a ListBox control but it isn't providing the control needed meet the spacing requirement of #1. Because of this, I am thinking the best approach is to do the math to determine the number of rows and columns, then simply use a Grid control and create the correct number of rows and columns.
I have created a UserControl to display the image and it's metadata, which will be displayed in each cell of the grid. The Image control in this UserControl has the mouse event to implement requirement #3.
Of course the big advantage to using a ListBox is the whole data binding and ItemTemplate. Is there some way I can implement data binding and the item template concept with the DataGrid?
Sam
RogerGu
Participant
870 points
255 Posts
10-29-2009 11:34 PM |
Take a look at the FlowControl.
Edit:
Sorry, I meant WrapPanel, from the controls toolkit
Twitter
10-29-2009 11:43 PM |
http://blogs.silverlight.net/blogs/justinangel/archive/2008/11/05/silverlight-toolkit-wrappanel.aspx
10-29-2009 11:55 PM |
I have played with the WrapPanel and it has the same spacing issues that the ListControl. The spacing needs to be even on all sides of all the images and the control frame. What happens with both the ListBox and WrapPanel is that there is more space to the right of each row. Depending on the heigth, images are cut off in the middle or there is dead space at the bottom. I need it to be nice and even all the way around the control. It needs to loom like a... Table! Sam
10-30-2009 9:59 AM |
You could just use a grid as you said, and populate it at runtime when you know the actual space it has to take up, then deside how many columns/rows it gets:
RowDefinition row = new RowDefinition(); ColumnDefinition column = new ColumnDefinition(); LayoutRoot.RowDefinitions.Add(row); LayoutRoot.ColumnDefinitions.Add(column);
10-30-2009 10:10 AM |
That is exactly what I am currently planing to do, which is why I initially asked:
Is there some way I can implement data binding and the item template concept with the DataGrid?
Maybe I should have simply said "Grid" rather then "DataGrid", my mistake.
Jonathan...
All-Star
24939 points
2,425 Posts
11-05-2009 10:32 PM |
Hi Eharleton,
ehcarleton:The table must be evenly spaced on all sides
That's based on your implement. For example, we can use two StackPanels. The inner StackPanel will be evenly spaced to the outer.
ehcarleton:Metadata is displayed with each image (name and tag state)
The inner StackPanel has a Image and several TextBlock to show the image and meta data.
ehcarleton:The user can double click on a image to fire an event to view a larger version of the image.
Double click event is not enabled with Image control. Here we need to achieve this in an alternative way. We can detect its MouseLeftButtonDown and interal of time between two MouseLeftButtonDown events.
For the page view function, please reference to DataPager sample here.
ehcarleton:Of course the big advantage to using a ListBox is the whole data binding and ItemTemplate. Is there some way I can implement data binding and the item template concept with the DataGrid?
The two StackPanels are embed into a Silverlight UserControl. How to binding the DataSource, we can expose Dependency Properties.
Best regards,
Jonathan
11-06-2009 9:41 PM |
Jonathan,
Thank you, I did not know about the DataPager. The backend is NOT Microsoft technology, so it looks like I will need to implement System.ComponentModel.IPagedCollectionView to get the data from the web service. When I try to create a class that implements System.ComponentModel.IPagedCollectionView, the interface is not found. What am I missing?
11-07-2009 10:53 AM |
I am very glad Microsoft is starting to warm to open source... I looked into the source code of the Silverlight Toolkit October 2009 and discovered that IPagedCollectionView is indeed in the System.ComponentModel namespace. Further more I discovered that it was in the System.Windows.Data folder, thus by adding the System.Windows.Data assembly, I can now reference it. Sam