473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to fill the grid/panel with the selected images from ListBox multiple selection

Hi,
I can only bind 1 item even if I selected more than 1 item from my ListBox. Every time I select another item, my uniformGrid(grid to display selected items) will only display the first selection not the other selected items.

My uniformGrid has 2 rows and 2 columns. I just want to fill them with my selected items(i.e. image) from my ListBox.
Problem Summary:
I just like to know how to fill any grid/uniformGrid/Stackpanel or whatever it takes to fill those item(i.e. image) selected from my listbox (SelectionMode=Multiple).

Thank You
Dec 5 '11 #1
1 4270
Frinavale
9,735 Expert Mod 8TB
Since you are binding to more than one thing, you should use a control whose purpose is to display more than one thing....like an ItemsControl

You can then set ItemsPanel property for that control to use the UniformGrid.

The following is a working example of what I'm talking about.
The array of strings are paths to the default sample images that come with Windows 7. If you aren't using Windows 7, then modify the paths to point to existing images.

Expand|Select|Wrap|Line Numbers
  1. <Grid>
  2.     <Grid.ColumnDefinitions>
  3.         <ColumnDefinition Width="Auto" />
  4.         <ColumnDefinition Width="*" />
  5.     </Grid.ColumnDefinitions>
  6.     <Grid.Resources>
  7.         <x:Array x:Key="ImagePaths" Type="sys:String" 
  8.                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  9.                      xmlns:sys="clr-namespace:System;assembly=mscorlib">
  10.             <sys:String>C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg</sys:String>
  11.             <sys:String>C:\Users\Public\Pictures\Sample Pictures\Desert.jpg</sys:String>
  12.             <sys:String>C:\Users\Public\Pictures\Sample Pictures\Hydrangeas.jpg</sys:String>
  13.             <sys:String>C:\Users\Public\Pictures\Sample Pictures\Jellyfish.jpg</sys:String>
  14.             <sys:String>C:\Users\Public\Pictures\Sample Pictures\Koala.jpg</sys:String>
  15.             <sys:String>C:\Users\Public\Pictures\Sample Pictures\Lighthouse.jpg</sys:String>
  16.             <sys:String>C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg</sys:String>
  17.             <sys:String>C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg</sys:String>
  18.         </x:Array>
  19.     </Grid.Resources>
  20.     <ListBox x:Name="ImageList" 
  21.                  SelectionMode="Multiple" 
  22.                  Grid.Row="0" Grid.Column="0" 
  23.                  ItemsSource="{StaticResource ImagePaths}">
  24.         <ListBox.ItemTemplate>
  25.             <DataTemplate>
  26.                 <Image Source="{Binding}" Width="70"/>
  27.             </DataTemplate>
  28.         </ListBox.ItemTemplate>
  29.     </ListBox>
  30.     <ItemsControl ItemsSource="{Binding ElementName=ImageList, Path=SelectedItems}"  Grid.Row="0" Grid.Column="1">
  31.         <ItemsControl.ItemsPanel>
  32.             <ItemsPanelTemplate>
  33.                 <UniformGrid Background="Cornsilk" Columns="2" />
  34.             </ItemsPanelTemplate>
  35.         </ItemsControl.ItemsPanel>
  36.         <ItemsControl.ItemTemplate>
  37.             <DataTemplate>
  38.                 <Grid HorizontalAlignment="Center" VerticalAlignment="Top" Margin="1">
  39.                     <Border Opacity=".2" Background="Black" BorderBrush="Black" BorderThickness="5" CornerRadius="5"></Border>
  40.                     <Image Source="{Binding}" Margin="5" />
  41.                 </Grid>
  42.             </DataTemplate>
  43.         </ItemsControl.ItemTemplate>
  44.     </ItemsControl>
  45. </Grid>
-Frinny
Jan 11 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: DK | last post by:
Hello everybody ! I need little help from Your side. I have form called Form2, and ListBox called List 20. Property of List 20 allow multiple selection. Also I have query called Distribution as...
5
by: Dave H | last post by:
I have an asp:listbox, allowing multiple selections, is there a quick check to see if there's more than one selected, or do I need to go through the whole list? Thanks, Dave
0
by: Robin Tucker | last post by:
Hi there, I have a list box (just happens to be owner draw). When I select multiple items using the CTRL key, the items I have selected become highlighted (obviously). Now, when I click on one...
1
by: barbara_dave | last post by:
Hi, all, I know Listbox control has multiple and single mode for item selection. I need to use multiple selection mode, but I like to select items with shift or ctrl key and mouse. The reason...
10
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code:...
0
by: Waran | last post by:
Hi, I have form where i am using a listbox where we can select multiple values.I am storing the selected values concatenating with commas(for eg. "22,21,19,16").Now i have to update this form, so...
2
abouddan
by: abouddan | last post by:
Hi all First I am using Access 2000, In my project I have 3 tables. The first one 'Employe' contains the data of employees, and each employe has a unique ID. The second table is 'Peripheral', It...
0
by: linda.s | last post by:
Hi, I wonder how to hold the ctrl key and left button (button-1) to do multiple selection of the following items? Thanks, Linda import Tkinter s = Tkinter.Scrollbar() L = Tkinter.Listbox()
1
by: manivelk | last post by:
Hi there, I try to create a ListBox with multiple selection. The ListBox is filled with Data from a database once on Page_Load. When I click the button to submit the form all selections will...
4
by: vibhakhushi | last post by:
Hello all, How to get a checkbox column in a grid panel? I want to have both normal columns and also a column of checkbox. Finally i read the record row wise not based on the checkbox which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.