i’m trying to achieve a functionality but i’m don’t know how to start it.
I’m using vs 2008 sp1 and i’m consuming a webservice which returns a collection (is contactInfo[]) that i bind to a ListBox with little datatemplate on it.
<ListBox Margin="-146,-124,-143,-118.808" Name="contactListBox" MaxHeight="240" MaxWidth="300" MinHeight="240" MinWidth="300">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock>
<CheckBox Name="contactsCheck" Uid="{Binding fullName}" Checked="contacts_Checked" /><Label Content="{Binding fullName}" FontSize="15" FontWeight="Bold"/> <LineBreak/>
<Label Content="{Binding mobile}" FontSize="10" FontStyle="Italic" Foreground="DimGray" /> <Label Content="{Binding email}" FontStyle="Italic" FontSize="10" Foreground="DimGray"/>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Every works fine so far. so When a checkbox is checked i’ll like to access the information of the labels (either the) belonging to the same row or attached to it and append the information to a global variable for example (for each checkbox checked).
My problem right now is that i don’t know how to do that.
Can any one shed some light on how to do that?
if you notice Checked="contacts_Checked" that’s where i planned to perform the operations. thanks for reading and helping out
I hear you asking to get the “information of the labels” from the row, and TimothyP has tried to explain how to do that. I could improve on his answer in several ways, but I think you are probably not asking the question you really meant to ask.
If you want to get the data that is displayed in the labels, the easy way is to simply do that. For example, with your original template:
This is generally a better way to do things than to read data directly out of labels.
If you want to get all Content from all the labels beside the checkbox in the visual tree, you can do it like this:
Personally I don’t think this is as nice.
Note that you can also change this solution to use the label name to indicate which labels you want to include: