Reputation: 189
I have implemented a listbox with buttons as follows
<Button.Content>
<StackPanel Orientation="Horizontal" Width="440" Height="210">
<Image Source="{Binding Image}" Height="120" Width="120"/>
<StackPanel Orientation="Vertical" Height="200">
<StackPanel Orientation="Horizontal" Height="40">
<TextBlock Width="100" Text="TITLE" Height="40" FontSize="22"/>
<TextBlock Width="220" Text="{Binding Title}" Height="40" FontSize="22"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Height="40">
<TextBlock Width="100" Text="Detail" Height="40" FontSize="22"/>
<TextBlock Width="220" Text="{Binding description}" Height="40" FontSize="22"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Height="40">
<TextBlock Width="100" Text="Discount" Height="40" FontSize="22"/>
<TextBlock Width="220" Text="{Binding discount}" Height="40" FontSize="22"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Height="40" >
<TextBlock Width="100" Text="Deal ID" Height="40" FontSize="22"/>
<TextBlock Name="dealID" Width="220" Text="{Binding DID}" Height="40" FontSize="22"/>
</StackPanel>
</StackPanel>
</StackPanel>
</Button.Content>
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Now the problem that i face is when i click the button i want to get the value of dealID thats in the last text block binded to DID. For this i created the event handler for button click as follows
private void Button_Click(object sender, RoutedEventArgs e)
{
Button myButton = sender as Button;
}
Now i dont have any clue what to do next the mybutton.content method is not working for me
Upvotes: 0
Views: 309
Reputation: 7480
I suggest you to use Blend for that, you can declare click event on xaml, its more easy.
Upvotes: 1
Reputation: 9314
u might want to cast the mybutton.content to the template that you have written inside the content i.e. to a stackpanel..
Upvotes: 0