2014-02-25 50 views
0

我想點擊列表框項目點擊事件並獲取點擊項目,但點擊事件沒有點火,請幫助。點擊事件不在MVVM的Windows Phone 8中工作

<ListBox Margin="0,40,0,0" 
     ItemsSource="{Binding Documents}" IsHitTestVisible="True" 
     Width="450" 
     VirtualizingStackPanel.VirtualizationMode="Recycling"> 

    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <toolkit:WrapPanel Orientation="Horizontal" /> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <Grid Height="150" Margin="5" 
        Width="150" Background="Aqua"> 
       <TextBlock Text="{Binding Name}" VerticalAlignment="Center" HorizontalAlignment="Center" /> 

       <i:Interaction.Triggers> 
        <i:EventTrigger EventName="Tap"> 
         <commands:MvxEventToCommand Command="{Binding OpenFileCommand}" /> 
        </i:EventTrigger> 
       </i:Interaction.Triggers> 
      </Grid> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

回答

3

你確定這個活動永遠不會被解僱嗎?也許你是在網格外面挖掘?列表框內的項目內容(在這種情況下爲網格)不會在整個列表框寬度範圍內延伸,它默認是左對齊的。要確認,請嘗試點擊列表框項目的最左側區域,查看是否用該項目觸發了該事件。

假設問題是由未拉伸列表框項內容造成的,您可以嘗試設置HorizontalContentAlignment="Stretch"來解決它:

<ListBox.ItemContainerStyle> 
    <Style TargetType="ListBoxItem"> 
     <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 
    </Style> 
</ListBox.ItemContainerStyle> 
+0

只是好奇,如果這真的有效/無效。你可否確認? – har07

相關問題