Click here to Skip to main content
16,007,443 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Scheduler Pin
aruna_koride24-Apr-08 13:02
aruna_koride24-Apr-08 13:02 
QuestionStandardising Styles Accross Multiple Applications Pin
Jammer23-Apr-08 23:08
Jammer23-Apr-08 23:08 
GeneralRe: Standardising Styles Accross Multiple Applications Pin
Pete O'Hanlon24-Apr-08 0:18
mvePete O'Hanlon24-Apr-08 0:18 
GeneralRe: Standardising Styles Accross Multiple Applications Pin
Jammer24-Apr-08 0:51
Jammer24-Apr-08 0:51 
GeneralRe: Standardising Styles Accross Multiple Applications Pin
Pete O'Hanlon24-Apr-08 1:04
mvePete O'Hanlon24-Apr-08 1:04 
GeneralRe: Standardising Styles Accross Multiple Applications Pin
Jammer24-Apr-08 1:13
Jammer24-Apr-08 1:13 
GeneralRe: Standardising Styles Accross Multiple Applications Pin
Jammer24-Apr-08 6:06
Jammer24-Apr-08 6:06 
QuestionDatabinding Image to BitmapImage [modified] Pin
dlarkin7723-Apr-08 5:30
dlarkin7723-Apr-08 5:30 
Hi,

I am trying to add some images to a listbox as described in Josh Smith's excellent article <a href="http://www.codeproject.com/KB/WPF/CustomListBoxLayoutInWPF.aspx">here</a>.

The only twist is that I need to bind to a list of BitmapImages that are created using a MemoryStream.
The images are being read from a database and I don't want to have to save them locally before showing them in the listbox.
I am not getting any errors - there are just no images being displayed.
I have taken the XAML entirely as is from Josh's article (I did try changing the Image binding from UriSource to StreamSource but that didn't work).
I'm pretty new to WPF so I'm probably doing something something really stupid, can anyone suggest what it is?

<code>
public static List<BitmapImage> GetProductImages() {
List<BitmapImage> images = new List<BitmapImage>();

using (SqlConnection cn = new SqlConnection(cnString)) {
string sql = "SELECT Top 10 ProductImage From Products WHERE NOT (ProductImage IS NULL)";
SqlCommand cmd = new SqlCommand(sql);
cmd.Connection = cn;
cmd.Connection.Open();

SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read()) {
byte[] productImage = null;
productImage = (byte[])reader["ProductImage"];
if (productImage != null) {
System.IO.MemoryStream ms = new System.IO.MemoryStream(productImage);
BitmapImage bm = new BitmapImage();
bm.BeginInit();
bm.StreamSource = ms;
bm.EndInit();
images.Add(bm);
}
}
cmd.Connection.Close();
}
return images;
}
</code>

Thanks very much,

dlarkin77

Edit: I don't know why that link doesn't appear as a clickable link or why the code isn't in a code block. Sorry about that!

<div class="ForumMod">modified on Wednesday, April 23, 2008 11:46 </div>
GeneralRe: Databinding Image to BitmapImage Pin
User 27100923-Apr-08 6:00
User 27100923-Apr-08 6:00 
GeneralRe: Databinding Image to BitmapImage Pin
dlarkin7723-Apr-08 6:18
dlarkin7723-Apr-08 6:18 
GeneralRe: Databinding Image to BitmapImage Pin
User 27100923-Apr-08 6:47
User 27100923-Apr-08 6:47 
GeneralRe: Databinding Image to BitmapImage [modified] Pin
Pete O'Hanlon23-Apr-08 9:07
mvePete O'Hanlon23-Apr-08 9:07 
GeneralRe: Databinding Image to BitmapImage Pin
dlarkin7723-Apr-08 23:36
dlarkin7723-Apr-08 23:36 
GeneralNeed WPF Defination Pin
M Riaz Bashir22-Apr-08 21:34
M Riaz Bashir22-Apr-08 21:34 
GeneralRe: Need WPF Defination Pin
Pete O'Hanlon22-Apr-08 23:13
mvePete O'Hanlon22-Apr-08 23:13 
GeneralRe: Need WPF Defination Pin
RNEELY24-Apr-08 5:04
RNEELY24-Apr-08 5:04 
QuestionHow to set mouse position? Pin
Yoyosch20-Apr-08 22:01
Yoyosch20-Apr-08 22:01 
AnswerRe: How to set mouse position? Pin
Pete O'Hanlon21-Apr-08 8:29
mvePete O'Hanlon21-Apr-08 8:29 
GeneralRe: How to set mouse position? Pin
Yoyosch21-Apr-08 23:46
Yoyosch21-Apr-08 23:46 
GeneralRe: How to set mouse position? Pin
Pete O'Hanlon22-Apr-08 0:53
mvePete O'Hanlon22-Apr-08 0:53 
GeneralRe: How to set mouse position? Pin
Yoyosch22-Apr-08 5:49
Yoyosch22-Apr-08 5:49 
GeneralRe: How to set mouse position? Pin
Pete O'Hanlon22-Apr-08 8:41
mvePete O'Hanlon22-Apr-08 8:41 
GeneralRe: How to set mouse position? Pin
User 27100922-Apr-08 5:59
User 27100922-Apr-08 5:59 
GeneralOT: MVP Summit Pin
Colin Angus Mackay22-Apr-08 6:42
Colin Angus Mackay22-Apr-08 6:42 
GeneralRe: OT: MVP Summit Pin
User 27100922-Apr-08 7:43
User 27100922-Apr-08 7:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.