Note that there are some explanatory texts on larger screens.

plurals
  1. POGettting the values of TextBox from a data bound ListBox
    primarykey
    data
    text
    <p>Hello I need to get the values from Listbox selected items. Note that, the data templates are in data bound. here is the xaml : </p> <pre><code>&lt;ListBox Name="AppointmentResultsData" ItemsSource="{Binding}" Height="650" Width="480" Margin="24,0,0,0" Foreground="#CBF7FA" SelectionChanged="AppointmentResultsData_SelectionChanged"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;/Grid.RowDefinitions&gt; &lt;TextBlock Text="{Binding Path=Subject, Mode=TwoWay}" TextWrapping="Wrap" FontSize="30" Grid.Column="0" Grid.Row="1"/&gt; &lt;Grid Grid.Column="0" Grid.Row="2"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition/&gt; &lt;ColumnDefinition/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;/Grid.RowDefinitions&gt; &lt;TextBlock Text="{Binding Path=Account.Name}" Grid.Column="0" Grid.Row="1" FontSize="28"/&gt; &lt;TextBlock Text="Start : " Grid.Column="0" FontSize="22" Grid.Row="2"/&gt; &lt;TextBlock Text="{Binding Path=StartTime}" FontSize="22" Grid.Column="1" Grid.Row="2"/&gt; &lt;TextBlock Text="End : " Grid.Column="0" Grid.Row="3" FontSize="22"/&gt; &lt;TextBlock Text="{Binding Path=EndTime}" Grid.Column="1" FontSize="22" Grid.Row="3"/&gt; &lt;TextBlock Text="Location : " Grid.Column="0" Grid.Row="4" FontSize="22"/&gt; &lt;TextBlock Text="{Binding Path=Location}" Grid.Column="1" FontSize="22" Grid.Row="4"/&gt; &lt;TextBlock Text="Status : " Grid.Column="0" FontSize="22" Grid.Row="5"/&gt; &lt;TextBlock Text="{Binding Path=Status}" Grid.Column="1" FontSize="22" Grid.Row="5"/&gt; &lt;/Grid&gt; &lt;TextBlock Text=" "/&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>I need values of the textboxes in selection changed event.I have tried like this...</p> <pre><code>private void AppointmentResultsData_SelectionChanged(object sender, SelectionChangedEventArgs e) { //SelectedEvent seleted = AppointmentResultsData.SelectedItem as SelectedEvent; if (AppointmentResultsData.SelectedIndex == -1) return; ListBoxItem currentSelectedListBoxItem = this.AppointmentResultsData.ItemContainerGenerator.ContainerFromIndex(AppointmentResultsData.SelectedIndex) as ListBoxItem; if (currentSelectedListBoxItem == null) return; // Iterate whole listbox tree and search for this items TextBox nameBox = helperClass.FindDescendant&lt;TextBox&gt;(currentSelectedListBoxItem); TextBlock nameBlock = helperClass.FindDescendant&lt;TextBlock&gt;(currentSelectedListBoxItem); MessageBox.Show(nameBlock.Text + " " + nameBox.Text); } </code></pre> <p>But it didn't work !</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