c# - Silverlight WrapPanel Children -


What is the best way to add children to a rapapelle in silver light? I am using C # and I am reading in a JSON object with images with thumbnails and related information.

The final goal is a grid of thumbnails (13 thumbs horizontally vertically by 6 thumbs up to 950px).

When you have to face adding items to the code, then there is usually a better method .

To create a list box and set your items in your list (or about binding it with datacentext) to display your thumbnails + information and then create a data timeplate (this Important part is) Create an item panil template using a WrapPanel.

  & lt; Grid X: Name = "ImageTimble" & gt; & Lt; ListBox ItemsSource = "{Binding}" width = "950" ScrollViewer.HorizontalScrollBarVisibility = "Disabled" & gt; & Lt; ListBox.ItemTemplate & gt; & Lt; DataTemplate & gt; & Lt; StackPanel Orientation = "Vertical" & gt; & Lt; Image source = "{binding thumbnail}" width = "80" height = "60" /> & Lt; Text block text = "{binding image name}" /> & Lt; / StackPanel & gt; & Lt; / DataTemplate & gt; & Lt; /ListBox.ItemTemplate> & Lt; ListBox.ItemsPanel & gt; & Lt; ItemsPanelTemplate & gt; & Lt; WrapPanel Orientation = "horizontal" /> & Lt; / ItemsPanelTemplate & gt; & Lt; /ListBox.ItemsPanel> & Lt; / ListBox & gt; & Lt; / Grid & gt;  

Then in your code, once you get your data from your JSON call:

  this.ImageThumbnails.DataContext = thumbnailListFromJSON;  

Now if your list is an overview, any change in the list will automatically appear in your UI.

(pseudo-code above code - obviously you want to change it to reflect your data structure)

Edit: Added ScrollViewer.HorizontalScrollBarVisibility = "Disabled" This is important for ListBox because this scroll viewer is expanding horizontally in infinity. 1-line list without this wrappane.


Comments