Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read the selected item from a listpicker in WP7?
    primarykey
    data
    text
    <p>I have the following listpicker in my XAML;</p> <pre><code>&lt;toolkit:ListPicker Name="CategoryPicker" ItemsSource="{Binding Category}" CacheMode="BitmapCache" FullModeHeader="{Binding Path=Resources.TheHeader}" SelectedIndex="{Binding TheCurrentIndex, Mode=OneWay}" IsEnabled="{Binding IsViewEnabled}" TabIndex="0" Margin="12,229,12,-205" SelectionChanged="CategoryPicker_SelectionChanged"&gt; &lt;toolkit:ListPicker.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Orientation="Horizontal" HorizontalAlignment="Center"&gt; &lt;TextBlock Text="{Binding CategoryDesc}" 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 CategoryDesc}" FontSize="40" TextWrapping="Wrap" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/toolkit:ListPicker.FullModeItemTemplate&gt; </code></pre> <p></p> <p>I have been able to populate the listpicker from a SQL CE data table via LINQ, but I am struggling to retrieve the value of the selecteditem.</p> <p>I have tried the following;</p> <pre><code>ListPickerItem selectedItem = CategoryPicker.ItemContainerGenerator.ContainerFromItem(this.CategoryPicker.SelectedItem) as ListPickerItem; </code></pre> <p>I don't think I have understood this properly but I can't seem to to read the text value of the selected item, all help, as always, is appreciated!</p> <h2>edit</h2> <p>The original table definition for categories is below;</p> <pre><code>[Table(Name = "Categories")] public class Categories : INotifyPropertyChanged, INotifyPropertyChanging { // Define ID: private field, public property and database column. private int _categoryId; [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)] public int CategoryId { get { return _categoryId; } set { if (_categoryId != value) { NotifyPropertyChanging("CategoryId"); _categoryId = value; NotifyPropertyChanged("CategoryId"); } } } // Define item category: private field, public property and database column. private string _categoryDesc; [Column] public string CategoryDesc { get { return _categoryDesc; } set { if (_categoryDesc != value) { NotifyPropertyChanging("CategoryDesc"); _categoryDesc = value; NotifyPropertyChanged("CategoryDesc"); } } } #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; // Used to notify the page that a data context property changed private void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } #endregion #region INotifyPropertyChanging Members public event PropertyChangingEventHandler PropertyChanging; // Used to notify the data context that a data context property is about to change private void NotifyPropertyChanging(string propertyName) { if (PropertyChanging != null) { PropertyChanging(this, new PropertyChangingEventArgs(propertyName)); } } #endregion } </code></pre> <p>The property for Category is;</p> <pre><code>private ObservableCollection&lt;DBControl.Categories&gt; _category; public ObservableCollection&lt;DBControl.Categories&gt; Category { get { return _category; } set { if (_category != value) { _category = value; NotifyPropertyChanged("Category"); } } } </code></pre> <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.
 

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