|
Ahh ok ... theme DLL's it is then. I thought that would be the best solution to this particular issue.
Thanks chap.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Thanks for this Pete, I've pretty much got a working style.dll done now. Lots of tweaking to do and wotnot but this is indeed a seriously neat solution.
Just a quick one, do you have any neat tricks that you found on your journey down this route?
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
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>
|
|
|
|
|
|
Hi,
Thanks for that tip.
The memory stream does indeed contain data. For testing purposes I've used the stream to save the image data as a file locally and then used this file to create the BitmapImage and that works fine. Can you suggest anything else?
Thanks very much,
dlarkin77
|
|
|
|
|
Did you check out the two posts? They contain sample code for getting this to work. I'm sure it's something very simple since you are 98% there.
I'll try and write a sample, ( Karl does VB.NET but will be simple to translate or read ) tonight and post it.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
If you step through the code, what do you see at the line bm.StreamSource = ms ? Before you allocate the source, try setting ms.Position = 0; Alternatively, you can use ms.Seek(0, SeekOrigin.Begin);
-- Edit. The behaviour you are seeing is because the position of the pointer in the MemoryStream is pointing to the end when you have loaded it. You need to reset it back to the start before you can use it.
modified on Wednesday, April 23, 2008 5:30 PM
|
|
|
|
|
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
|
|
|
|
|
Hi,
I need compelete defination about WPF. Kindly give reference to download said information.
Thank you
(Riaz)
|
|
|
|
|
|
|
How to set mouse position? Something opposite to Mouse.GetPosition(container)
Thanks for help
|
|
|
|
|
Off the top of my head (and without firing up Visual Studio to check) I believe you would use Cursor.Position = new Point(x, y); .
|
|
|
|
|
So fire up VS and see that ur answer is silly
|
|
|
|
|
Yoyosch wrote: So fire up VS and see that ur answer is silly
Nope. I just ran it and it worked fine for me. Have you tried it?
|
|
|
|
|
Of course. This works in WinForms but not in WPF
|
|
|
|
|
There's nothing stopping you adding the WinForms reference to WPF and doing this.
|
|
|
|
|
Yoyosch,
Pete is trying to help you. Telling a Code Project MVP that his answer is silly does not promote good lines of communication. Thanks for working with us as we try and answer questions here.
Have a nice day.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Sorry I missed you at the MVP summit last week. I did, however, manage to speak to a few people that know you and you received some very high praise indeed.
|
|
|
|
|
Colin,
Me too. Don't know how we missed hooking up. Guess I'll just have to come and visit or get you to come to Charlotte!
Was very nice to meet so many cool and very smart developers. Super week for everyone.
Best to you always!
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Hi there,
I have a stackpanel which contains another stackpanel in which I can browse with a previous and next button. The inside stackpanel contains images . I would like that there is no end in this stack. I mean that the last picture and the first one are joinded.
Thanks in advance,
Globosky
|
|
|
|
|
You are referring to a carousel. Infragistics has one and there are others you can dowload and learn from. You can use their's or write you own.
Check out the recent WPF Panel and WPF 3D Panel artciles here on Code Project.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Is it possible to use Ajax in WPF Browser Application ?
Best Regards
-----------------
Abhijit Jana
Microsoft Certified Professional
"Success is Journey it's not a destination"
|
|
|
|
|
Yes it is....
All depends on how do you want to make your communications to the server, but you will be enabled to do it ONLY with the server that send you the xbap... that means that if you are trying to run your app from VS2008 and it is configured to open your browser to the file repository you will be not able to test any AJAX, you need to publish it to an IIS and then your AJAX response should be on that same server instance. or at least on that host -no reference to a por number restrictions on the documentation-.
Greetings
Carlos de Luna
|
|
|
|
|
Hi colleagues,
I'm dealing with a weird scenario that I will try to explain here. I don't know what more can I do to find a solution, so I'm posting here with the expectation that someone can help me.
I created a user control using WPF & C# in .NET 3.5 with VS2008. This control is placed in a dll. The control has a toolbar, a tree view on the right side and a browser on the left. Inside the XAML code, I'm inserting the WebBrowser control hosted in a WindowsFormsHost. If I use this control from a Container that uses WPF as well everything works fine.
The problems arise when I try to call the mentioned control from an MFC application. I created a modeless dialog and call my WPF control. The first problem was that WM_CHARS messages were eaten up by someone, and I didn't receive any keystroke in my WPF control. Hopefully, I found this useful link that helped me to solve the problem:
http://devonethatdevelops.wordpress.com/2007/10/30/wpf-win32-interop-with-hwndsource/
But the main problem is that when I put the focus in the web browser and press the TAB key, both the modeless dialog and the application hang. The only thing I can do is go to the task manager and end the process. I've been searching similar problems but found nothing. I've tried to put breakpoints on every KeyDown event both in the containing dialog and in the user control but nothing happens. It seems as though the TAB key absolutely swollen by don't-know-who.
I've executed the WPF control from a WPF container and the KeyDown events reach my control on every key I press, but when I call it from the MFC dialog the program don't stop in the breakpoints.
The only thing I know is that pressing the TAB key inside the web browser control frozens the application.
Please, do you have any idea of what could be happening? Any clue?
Well, thanks anyway for having had the patience of reading this.
Oscar Ortega
|
|
|
|