newbie question: WPF Data Binding - when to use "dynamic resource"

I

indtaz

I am new to WPF and DataBinding.
I am trying to create a listbox that will display a list of images in
a stackpanel.
The images themselves are retried from a table defined in SQL Server.
( Database used is the AdventureWorks database)

I am currently able to retrieve the images from the database using an
SQL query.
However, I am not sure, how to implement the binding to display the
images in the listbox.
I am unclear about when/how to use "Static Resource" and "Dynamic
Resource" for Data Binding.

Any pointers would be much appreciated.
 
M

Marc Vangrieken

Hi,

I'm fairly new to WPF myself, so maybe other can correct me where i'm
wrong... Afaik resources are things that are declared in a resources
section (eg. Window.Resources) and although you could use them in this
scenario it's unneeded. One thing you could do is set the DataContext
of the ListBox to the structure that contains you images (eg.
ImageCollection) retrieved from the database and then make an
itemtemplate like this:

<ListBox Name="listView1" ItemsSource="{Binding ImageCollection}"
Background="Black"
Margin="0,116,0,0">
<ListBox.ItemsPanel>
<ItemsPanelTemplate >
<StackPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Path=ImageCollection}" Width="70"
Stretch="Fill" Margin="5"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

Now, you can take this one step further and make for instance your
ItemTemplate a static resource. You can than bind the listboxs
ItemTemplate property using the StaticResource syntax..

I hope this helped..

Marc Vangrieken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top