Reputation: 1096
I have a listbox where each row of listbox contains 2 textblock and 2 button. Whenever i click 1st button of any row of listbox then it will show the text of 1st textblock of that row from the listbox and whenever i click the 2nd button of any row of listbox it will speak the text of the 1st textblock of that row. Consider the bellow picture of listbox.If i click the star button of 2nd row it will show "sedulous" and if i click the the speaker button of the last row it will speak "underbid". How can i do that??? My list looks like this:
My listbox design in xaml looks like this:
<ListBox x:Name="listBox1" FontSize="26" Width="400" Height="Auto" HorizontalContentAlignment="Stretch" SelectionChanged="listBox1_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Eng}" Width="150"/>
<Button Content="" Height="Auto" Name="b1" Width="100" BorderThickness="0" Background="DarkGreen" />
<Button Content="" Height="Auto" Name="b2" Width="100" BorderThickness="0" Background="DarkGreen" />
</StackPanel>
<TextBlock Text="{Binding Path=Bng}" Width="150"/>
<Rectangle Height="2" Width="400" Fill="YellowGreen" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
And my code for making the list is:
List<dataLists> mylist = new List<dataLists>();
string word = textBox1.Text;
if (db != null)
{
var contacts = (from m in db.Dics where m.English.StartsWith(word) select new { m.English, m.Bangla }).Take(5);
string s1, s2;
try
{
foreach (var a in contacts)
{
s1 = a.English;
s2 = a.Bangla;
mylist.Add(new dataLists() { Eng = s1, Bng = s2 });
}
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
listBox1.ItemsSource = mylist;
Can anyone have any solution of this??
Upvotes: 0
Views: 865
Reputation: 2617
you can easily manage this in button's onclick event, set tag as textblock's text and
in onclick event
textbox.text = (sender as button).Tag.Tostring()
Upvotes: 1