Note that there are some explanatory texts on larger screens.

plurals
  1. PODatabound ListPicker SelectedItem goes blank when modifying SelectedIndex
    text
    copied!<p>I have a ListPicker in my Windows Phone 7 app where both the <strong>ItemsSource</strong> and <strong>SelectedIndex</strong> properties are bound to my ViewModel. SelectedIndex is using <strong>Two Way</strong> binding. The items and the SelectedIndex are correctly populated on application startup. However, when I modify the SelectedIndex property in my ViewModel the ListPicker's TextBox goes blank, as if there was no selected item. If I go to full mode and check which is the selected item from the list, the correct item is being selected.</p> <p>Here is the ListPicker xaml code:</p> <pre><code>&lt;toolkit:ListPicker Name="TheListPicker" ItemsSource="{Binding TheItems}" CacheMode="BitmapCache" FullModeHeader="{Binding Path=Resources.TheHeader, Source={StaticResource LocalizedStrings }}" SelectedIndex="{Binding TheCurrentIndex, Mode=TwoWay}" IsEnabled="{Binding IsViewEnabled}" TabIndex="0" &gt; &lt;toolkit:ListPicker.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Orientation="Horizontal" HorizontalAlignment="Center"&gt; &lt;TextBlock Text="{Binding Name}" FontFamily="{StaticResource PhoneFontFamilySemiBold}" FontSize="{StaticResource PhoneFontSizeMediumLarge}" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/toolkit:ListPicker.ItemTemplate&gt; &lt;toolkit:ListPicker.FullModeItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel x:Name="item" Orientation="Horizontal" Margin="5, 24, 0, 24"&gt; &lt;TextBlock Margin="15, 0, 0, 0" Text="{Binding Name}" FontSize="40" TextWrapping="Wrap" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/toolkit:ListPicker.FullModeItemTemplate&gt; &lt;/toolkit:ListPicker&gt; </code></pre> <p>This is a simplified version of my ViewModel:</p> <pre><code>[DataMember] public ObservableCollection&lt;ItemEntity&gt; TheItems { get { if (this.theItems == null) { this.theItems = new ObservableCollection&lt;ItemEntity&gt;(); } return this.theItems; } set { this.theItems = value; } } [DataMember] public int TheCurrentIndex { get { return this.theCurrentIndex; } set { if (value != this.theCurrentIndex) { this.theCurrentIndex = value; NotifyPropertyChanged("TheCurrentIndex"); NotifyPropertyChanged("IsSomeOtherPropertyEnabled"); } } } </code></pre> <p>And here is the relevant code from MainPage.xaml.cs (App_ViewModelChanged is an event handler invoked when some async stuff performed on application startup finishes):</p> <pre><code>private void App_ViewModelChanged(object sender, ViewModelChangedEventArgs e) { BindToViewModel(); } private void BindToViewModel() { this.DataContext = this.ViewModel; this.ViewModel.IsViewEnabled = true; } private void SomeAsyncMethodCompleted(object sender, DetectCompletedEventArgs e) { if (e.Error == null) { this.ViewModel.TheCurrentIndex = e.Result; } } </code></pre> <p>This issue is not happening all the time. Happens like 50% of the time. It seems to happen only once in the application lifetime and then never happens again. Also, the issue started appearing when I switched from the Feb 2011 release of the Silverlight Control Toolkit to the Aug 2011 release. Never had this issue before.</p> <p>Is this a known issue?</p>
 

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