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

WPF

 
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 
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 
Hi,

Pete:

I have tried as you suggested but still no joy. No doubt I'm doing something really stupid so I'll post the code that I use.

This is the code I use to get my list of BitmapImages:

private void Window_Loaded(object sender, RoutedEventArgs e) {
List<BitmapImage> images = GetProductImages();
lstProductImages.ItemsSource = images;
}

private 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"];
using (MemoryStream ms = new MemoryStream(productImage)) {
//ms.Seek(0, SeekOrigin.Begin);
ms.Position = 0;
BitmapImage bm = new BitmapImage();
bm.BeginInit();
//bm.CacheOption = BitmapCacheOption.OnLoad;
bm.StreamSource = ms;
bm.EndInit();
ms.Close();
images.Add(bm);
}
}
cmd.Connection.Close();
}
return images;
}


This is the XAML for the listbox:

<Window.Resources>
<Style TargetType="{x:Type ListBox}">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Border BorderBrush="Black" BorderThickness="4" CornerRadius="5" Margin="6">
<!--<Image
Source="{Binding Path=UriSource}"
Stretch="Fill"
Width="100" Height="120"/>-->
<Image
Source="{Binding Path=StreamSource}"
Stretch="Fill"
Width="100" Height="120"/>
</Border>
</DataTemplate>
</Setter.Value>
</Setter>

<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>

<Setter
Property="ScrollViewer.HorizontalScrollBarVisibility"
Value="Disabled"
/>
</Style>
</Window.Resources>

<Grid>
<ListBox Name="lstProductImages"/>
</Grid>

Does anything obvious jump out at you?


Karl:

I've looked at both of those sites and played around with what they suggested to no avail.

Thanks very much,

dlarkin77
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 
QuestionWPF and no end list Pin
asgardia19-Apr-08 13:05
asgardia19-Apr-08 13:05 
GeneralRe: WPF and no end list Pin
User 27100921-Apr-08 5:17
User 27100921-Apr-08 5:17 
QuestionWPF Browser Application With Ajax Pin
Abhijit Jana18-Apr-08 21:29
professionalAbhijit Jana18-Apr-08 21:29 
AnswerRe: WPF Browser Application With Ajax Pin
charlymoon23-Apr-08 12:21
charlymoon23-Apr-08 12:21 
QuestionWebBrowser hosted in a WPF user control called from MFC dialog hangs when pressing the TAB key. Pin
OscarOrtega18-Apr-08 6:28
OscarOrtega18-Apr-08 6:28 

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.