Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use CommandParameter. Using <code>{Binding}</code> will pass the object in the observable collection that was clicked. More at <a href="http://msdn.microsoft.com/en-us/library/ms752308.aspx#creating_commands" rel="nofollow">MSDN</a> </p> <pre><code>&lt;Button Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.OpenSessionCommand}" CommandParemeter="{Binding}" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="243" Height="42"&gt; &lt;TextBlock TextWrapping="Wrap"&gt; &lt;Run Text="{Binding SessionName}"/&gt;&lt;LineBreak/&gt; &lt;Run Text="{Binding Genre}"/&gt;&lt;Run Text=" - "/&gt; &lt;Run Text="{Binding Tempo}"/&gt; &lt;/TextBlock&gt; &lt;/Button&gt; </code></pre> <p>You will also need to adjust the OpenSessionCommand method signature to accept your parameter but that will depend on what Command implementation you are using.</p> <p><strong>UPDATE</strong></p> <p>Below is a generic implementation of DelegateCommand that accepts a parameter.</p> <pre><code>public class DelegateCommand&lt;T&gt; : ICommand where T : class { private readonly Action&lt;T&gt; _command; private readonly Func&lt;T, bool&gt; _canExecute; public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public DelegateCommand(Action&lt;T&gt; command, Func&lt;T, bool&gt; canExecute = null) { if (command == null) throw new ArgumentNullException(); _canExecute = canExecute; _command = command; } public void Execute(object parameter) { _command(parameter as T); } public bool CanExecute(object parameter) { return _canExecute == null || _canExecute(parameter as T); } } </code></pre> <p>Now when you define your ICommand it should be something like this:</p> <pre><code> public ICommand OpenSessionCommand { get { return new DelegateCommand&lt;Button&gt;(OpenSession); } } public void OpenSession(Button button) { ContinueReceiving = false; dispatcherTimer.Stop(); Messenger.Default.Send&lt;NavigateMessage&gt;(new NavigateMessage(SessionViewModel.ViewName, this)); } </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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