I avoided to ask this question, but the ListBox's selected index can no be set. I have read the other threads and applied the settings, but it doesn't work.
<ListBox ItemsSource="{Binding}"
HorizontalAlignment="Right"
Name="lstReading" Height="Auto"
SelectedIndex="{Binding BookmarkSelectedIndex}">
In the something.xaml.cs, I am settings
lstReading.DataContext = IQText;
Where, IQText is an IEnumerable<dictIQ>
and includes the BookmarkSelectedIndex
as data element. Other data elements from IQText can be used but the listindex can't be set. Could someone please let me know why?
Are you have
BookmarkSelectedIndex
inside ofdictIQ
class? So, you have oneBookmarkSelectedIndex
per item, not per collection!You can create separate property
BookmarkSelectedIndex
outside ofdictIQ
or create class that inherited fromObservalbeCollection<dictIQ>
and have additional propertyBookmarkSelectedIndex
:I hope you choose best solution suitable for you
use this code for select item at runtime...