2011-10-22 60 views
-1

當我有這樣獲取列表框項目內部控制的內容被點擊

<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> 

一個的ItemTemplate當我點擊一個ListBoxItem DataTemplate的內部按鈕,我想文本塊TXT的內容,找出列表框項目是單擊以追溯列表框綁定的列表(模型)中的索引。 但是從命令參數我不能得到任何東西,因爲我認爲有很多文本塊命名爲TXT。

請幫幫我!

回答

0

一個更好的辦法來解決,這是由CommandParameter結合到該項目的「東西」在DataContext的是這樣的:

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

這樣的結合不依賴於特定的控制存在,並具有一個具體的名字。