Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to select an item in LongListSelector using the MVVM-pattern?
    text
    copied!<p>I'm building application using the MVVM pattern. After clicking on one of the elements I want to see this element's details. I wrote this:</p> <p>XAML</p> <pre><code>&lt;phone:LongListSelector ItemsSource="{Binding Data}" Margin="0,0,0,158" SelectedItem="{Binding SelectedItem}"&gt; &lt;phone:LongListSelector.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Button&gt; &lt;!-- Command="{Binding ShowDetailsAction}"--&gt; &lt;Button.Template&gt; &lt;ControlTemplate&gt; &lt;TextBlock Text="{Binding Text}"&gt;&lt;/TextBlock&gt; &lt;/ControlTemplate&gt; &lt;/Button.Template&gt; &lt;/Button&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/phone:LongListSelector.ItemTemplate&gt; &lt;/phone:LongListSelector&gt; </code></pre> <p>ViewModel:</p> <pre><code>public IEnumerable SelectedItem { get { return _itemsControl; } set { if (_itemsControl == value) return; _itemsControl = value; // Test _mss.ErrorNotification("fd"); } } </code></pre> <p>I tried also using a command, which didn't work, too. </p> <p>This was the command part:</p> <pre><code>public ICommand ShowDetailsCommand { get; private set; } public ViewModel() { _loadDataCommand = new DelegateCommand(LoadDataAction); SaveChangesCommand = new DelegateCommand(SaveChangesAction); ShowDetailsCommand = new DelegateCommand(ShowDetailsAction); } private void ShowDetailsAction(object p) { _mss.ErrorNotification("bla bla"); } </code></pre> <p><strong>EDIT</strong></p> <p>ViewModel</p> <pre><code>private IEnumerable _itemsControl; public IEnumerable Data { get { return _itemsControl; } set { _itemsControl = value; RaisePropertyChanged("Data"); } } protected void RaisePropertyChanged(string propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } </code></pre> <p>Model</p> <pre><code>public string Text { get; set; } public DateTimeOffset Data { get; set; } </code></pre> <p><strong>EDIT2</strong></p> <pre><code>private MobileServiceCollection&lt;ModelAzure, ModelAzure&gt; _items; private readonly IMobileServiceTable&lt;ModelAzure&gt; _todoTable = App.MobileService.GetTable&lt;ModelAzure&gt;(); private async void RefreshTodoItems() { try { _items = await _todoTable.ToCollectionAsync(); } catch (MobileServiceInvalidOperationException e) { _mss.ErrorNotification(e.ToString()); } Data = _items; } </code></pre>
 

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