Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not my favorite approach since it uses the <code>XmlDataProvider</code> and <code>XPath</code> syntax (which I tend to always forget). But you can embed your static data as xml within your Window.Resources like so:</p> <pre><code>&lt;Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;Window.Resources&gt; &lt;XmlDataProvider x:Key="MyStaticData" XPath="StaticItems" &gt; &lt;x:XData&gt; &lt;StaticItems xmlns=""&gt; &lt;StaticItem&gt; &lt;ItemText&gt;Item #1&lt;/ItemText&gt; &lt;ItemImageSource&gt;/Image1.jpg&lt;/ItemImageSource&gt; &lt;/StaticItem&gt; &lt;StaticItem&gt; &lt;ItemText&gt;Item #2&lt;/ItemText&gt; &lt;ItemImageSource&gt;/Image2.jpg&lt;/ItemImageSource&gt; &lt;/StaticItem&gt; &lt;/StaticItems&gt; &lt;/x:XData&gt; &lt;/XmlDataProvider&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;ListBox&gt; &lt;ListBox.ItemsSource&gt; &lt;Binding Source="{StaticResource MyStaticData}" XPath="StaticItem" /&gt; &lt;/ListBox.ItemsSource&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Border&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Image Source="{Binding XPath=ItemImageSource}" Height="30" /&gt; &lt;TextBlock Text="{Binding XPath=ItemText}" VerticalAlignment="Center" /&gt; &lt;/StackPanel&gt; &lt;/Border&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>Then within your ListBox bind to the XmlDataProvider you specified and use the XPath notation within the bindings to drill down to the data you want the controls to bind to.</p> <p>This site has a couple good examples too: <a href="http://vbcity.com/blogs/xtab/archive/2010/12/24/more-xpath-examples-in-a-wpf-application.aspx" rel="nofollow">http://vbcity.com/blogs/xtab/archive/2010/12/24/more-xpath-examples-in-a-wpf-application.aspx</a></p> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload