Note that there are some explanatory texts on larger screens.

plurals
  1. POListBoxItems not highlighting selected item when bound from ItemsSource
    primarykey
    data
    text
    <p>I've been trying to nut this out for a while now and meanwhile I've searched the internet high and low I can't seem to find an answer that fits how my code is made. I've seen the results of pages like <a href="https://stackoverflow.com/questions/9287857/listbox-does-not-highlight-generated-itemsitemssource-works-fine-for-listboxit">>here&lt;</a> and <a href="https://stackoverflow.com/questions/8696443/how-to-programatically-select-an-item-in-a-data-bound-listbox-control">>here&lt;</a> and neither of those work.</p> <p>My code is very similar to the example code for a databound application, as follows:</p> <pre><code>&lt;ListBox ItemsSource="{Binding Items}" Name="MyListBox"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding LineOne}"/&gt; &lt;TextBlock Text="{Binding LineTwo}"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>Except for one minor difference, and that's that I bind the ItemsSource at runtime as opposed to design time, ie:</p> <pre><code>MyListBox.ItemsSource = listCollection; </code></pre> <p>listCollection in this case is an ObservableCollection of an object which looks like:</p> <pre><code>public class MyObject() { public string LineOne { get; set; } public string LineTwo { get; set; } } </code></pre> <p>For some reason I just cannot get the list to highlight the selected item in the list. Changing to doesn't work as Visual Studio does not allow both ItemTemplate and Resources to be in use in my code apparently.</p> <p>Any help at all?</p> <p>Regards, Jovin.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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