|
Hey Pete,
Its a lil girl! So cool ...
How do you store all the theme code though? Are you using DLLs that are distributed with your applications?
How do you manage that within a multi developer environment?
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Jammer wrote: Are you using DLLs that are distributed with your applications?
Yup.
Jammer wrote: How do you manage that within a multi developer environment?
By having a designer come up with the themes.
|
|
|
|
|
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"
|
|
|
|