Windows phone 7 单击listbox项时获取其内部控件的内容

Windows phone 7 单击listbox项时获取其内部控件的内容,windows-phone-7,data-binding,commandparameter,Windows Phone 7,Data Binding,Commandparameter,我有一个像这样的项目模板 <ListBox> <ListBox.ItemTemplate> <DataTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition />

我有一个像这样的项目模板

<ListBox>
    <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Button Grid.Row="0">
                            <Button.Template>
                                <ControlTemplate>
                                    <Border BorderBrush="AntiqueWhite" BorderThickness="1">
                                        <StackPanel Orientation="Horizontal" Background="Gray" Width="465">
                                            <Image Margin="2,0,10,0" Source="{Binding StateImage}" Stretch="None"/>
                                            <TextBlock Name="txt" Text="{Binding DateLabel}"/>
                                        </StackPanel>
                                    </Border>
                                </ControlTemplate>
                            </Button.Template>
                            <Custom:Interaction.Triggers>
                                <Custom:EventTrigger EventName="Click">
                                    <mx:EventToCommand Command="{Binding VisibilityListboxCommand}"
                                                       CommandParameter="{Binding EementName=txt, Path=Text}"
                                                           />
                                </Custom:EventTrigger>
                            </Custom:Interaction.Triggers>
                        </Button>
                        <ListBox Grid.Column="1" ItemsSource="{Binding WhatsonList, Mode=OneWay}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Border BorderBrush="Gray" BorderThickness="0,0,0,1" Padding="0,0,0,10">
                                        <Grid Margin="0,10,0,0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="100"/>
                                                <ColumnDefinition Width="360"/>
                                            </Grid.ColumnDefinitions>
                                            <StackPanel Grid.Column="0">
                                                <Button>
                                                    .....
                                                </Button>
                                                <CheckBox Template="{StaticResource CheckboxImageTemplate}" Margin="0,5,0,0"/>
                                            </StackPanel>
                                            <ListBox Grid.Column="1">
                                                .....
                                            </ListBox>
                                        </Grid>
                                    </Border>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

.....
.....
当我单击listboxitem datatemplate内的按钮时,我想获取textblock txt的内容,以了解单击哪个listbox项可以追溯listbox绑定的列表(模型)中的索引。 但从commandparameter我无法得到任何东西,因为我认为有许多名为txt的文本块


请帮帮我

解决此问题的更好方法是将CommandParameter绑定到项的DataContext中的'thing',如下所示:

<Custom:Interaction.Triggers>
    <Custom:EventTrigger EventName="Click">
        <mx:EventToCommand Command="{Binding VisibilityListboxCommand}"
                           CommandParameter="{Binding}" />
    </Custom:EventTrigger>
</Custom:Interaction.Triggers>

这样,绑定就不依赖于存在的特定控件以及具有特定名称的控件