Skip to main content

Microsoft Silverlight

Answered Question Image Gallery: UserControl in table style GridRSS Feed

(0)

ehcarleton
ehcarleton

Member

Member

9 points

44 Posts

Image Gallery: UserControl in table style Grid

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:

  1. The table must be evenly spaced on all sides
  2. Metadata is displayed with each image (name and tag state)
  3. The user can double click on a image to fire an event to view a larger version of the image.

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
RogerGu

Participant

Participant

870 points

255 Posts

Re: Image Gallery: UserControl in table style Grid

Take a look at the FlowControl.

Edit:

Sorry, I meant WrapPanel, from the controls toolkit

 

RogerGu
RogerGu

Participant

Participant

870 points

255 Posts

Re: Image Gallery: UserControl in table style Grid

http://blogs.silverlight.net/blogs/justinangel/archive/2008/11/05/silverlight-toolkit-wrappanel.aspx

 

ehcarleton
ehcarleton

Member

Member

9 points

44 Posts

Re: Image Gallery: UserControl in table style Grid

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

RogerGu
RogerGu

Participant

Participant

870 points

255 Posts

Re: Image Gallery: UserControl in table style Grid

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);
 

ehcarleton
ehcarleton

Member

Member

9 points

44 Posts

Re: Image Gallery: UserControl in table style Grid

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.

Sam

Jonathan Shen – MSFT
Jonathan...

All-Star

All-Star

24939 points

2,425 Posts

Microsoft
Answered Question

Re: Image Gallery: UserControl in table style Grid

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

Jonathan Shen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

ehcarleton
ehcarleton

Member

Member

9 points

44 Posts

Re: Image Gallery: UserControl in table style Grid

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?

Sam

ehcarleton
ehcarleton

Member

Member

9 points

44 Posts

Answered Question

Re: Image Gallery: UserControl in table style Grid

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

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities