title: Windows Phone 7 - Function for ListBox button
body: <p>I have list of items in ListBox.<br>
  All the items have buttons.<br>
  I want to show the selected items name when I click the button inside the ListBox (Not the list box items).</p>
  
  <p>My Xaml:-</p>
  
  <pre><code>&lt;ListBox SelectedIndex="{Binding SelectedIndex,Mode=TwoWay}"  
           SelectedItem="{Binding SelectedStudent, Mode=TwoWay}" Height="374" 
           ItemsSource="{Binding StudentDetails,Mode=TwoWay}" 
           HorizontalAlignment="Left" Margin="2,6,0,0" Name="listBox1" 
           VerticalAlignment="Top" Width="476" BorderBrush="#00410D0D"&gt;
      &lt;i:Interaction.Triggers&gt;
          &lt;i:EventTrigger EventName="Tap"&gt;
              &lt;i:InvokeCommandAction Command="{Binding EventPageCommand, Mode=OneWay}"/&gt;
          &lt;/i:EventTrigger&gt;
      &lt;/i:Interaction.Triggers&gt;
      &lt;ListBox.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;Border BorderBrush="Gray" Padding="5" BorderThickness="1"&gt;
                  &lt;StackPanel Orientation="Horizontal"&gt;
                      &lt;Border BorderBrush="Wheat" BorderThickness="1"&gt;
                          &lt;Image Name="ListPersonImage" Source="{Binding PersonImage}" 
                                 Height="100" Width="100" Stretch="Uniform" Margin="10,0,0,0"/&gt;
                      &lt;/Border&gt;
                      &lt;TextBlock Text="{Binding FirstName}" Name="firstName" Width="200" 
                                 Foreground="White" Margin="10,10,0,0" 
                                 FontWeight="SemiBold" FontSize="22"  /&gt;
  
                      &lt;Button Height="80" Width="80" Command="{Binding addPerson}" 
                              DataContext="{Binding DataContext, ElementName=listBox1}"&gt;
                          &lt;Button.Background&gt;
                              &lt;ImageBrush 
                                  ImageSource="/NewExample;component/Images/icon_increase.png" /&gt;
                          &lt;/Button.Background&gt;
                      &lt;/Button&gt;
                  &lt;/StackPanel&gt;
              &lt;/Border&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>Here when I click the 'addPerson' Button it should show the selected items name.<br>
  Now I have write the coding for List box 'SelectedItmes'.</p>
  
  <p>My ViewModel:-  </p>
  
  <pre><code> private MVVMListBoxModel selectedStudent;
  public MVVMListBoxModel SelectedStudent
  {
      get { return selectedStudent; }
      set
      {
          if (selectedStudent == value)
              return;
          selectedStudent = value;
          MessageBox.Show("Selected Item==&gt;" + selectedStudent.FirstName + " Selected Index==&gt;" + SelectedIndex);
          if (SelectedIndex == 0)
          {
              var rootFrame = (App.Current as App).RootFrame;
              rootFrame.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
          }
      }
  }
  </code></pre>
  
  <p>Here I can show the selected Name when I click the list box items.<br>
  But now I want to show when I click the button.<br>
  Is it possible to show the items when I click the button?</p>
  
  <p>Now I have tried like this:-</p>
  
  <pre><code>public ReactiveAsyncCommand addPerson { get; set; }
  
  public MVVMListBoxViewModel()
  {
      addPerson = new ReactiveAsyncCommand();
      addPerson.Subscribe(x =&gt;
      {
          MessageBox.Show("Button Clicked..!!");
              ListBox listbox = (ListBox)sender;
              ListBoxEventsModel items = (ListBoxEventsModel)listbox.SelectedItem;
              MessageBox.Show("Selected Name" + items.ToString());
      });
  }
  </code></pre>
  
  <p>But here I can not show the selected items.<br>
  Please let me any idea to solve this issue.</p>