2010-06-23 8 views
0

J'ai un ListBox, un IEnumerable est la source de données. Quand un ListBoxItem est cliqué, je veux accéder à cet objet pour pouvoir récupérer des données et afficher une autre fenêtre.PreviewMouseLeftButtonDown ne se déclenche pas

Voici mon ListBox XAML

  `<ListBox Name="listBox1" Margin="0" Width="1010" Height="275" BorderThickness="0" BorderBrush="{x:Null}" Cursor="Arrow" HorizontalAlignment="Center" VerticalAlignment="Top" SelectionMode="Single" FontFamily="DIN" ScrollViewer.HorizontalScrollBarVisibility="Hidden" Focusable="False" IsHitTestVisible="False" IsTextSearchEnabled="False" >` 

      <ListBox.ItemContainerStyle> 
       <Style TargetType="{x:Type ListBoxItem}"> 
        <EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListBox_MouseLeftButtonDown"></EventSetter> 
       </Style> 
      </ListBox.ItemContainerStyle> 
      <ListBox.ItemTemplate> 
       <DataTemplate DataType="{x:Type local:Offer}"> 
        <StackPanel Margin="0" Width="200" Height="275" Background="Black" Name="sp"> 
         <Image Source="{Binding Image}" Width="200" Height="131" Margin="0"></Image> 
         <TextBlock Padding="5" Background="Black" Text="{Binding Name}" Foreground="White" FontFamily="DIN medium" FontWeight="Bold" FontSize="16" Width="200" Margin="0"></TextBlock> 
         <TextBlock Padding="5,0,5,0" Background="Black" Text="{Binding Date}" Foreground="White" FontFamily="DIN medium" FontWeight="Bold" FontSize="14" Width="200" Margin="0"></TextBlock> 
         <TextBlock Padding="5" Background="Black" Text="{Binding Description}" Foreground="White" FontFamily="DIN light" FontSize="16" Width="200" Margin="0" TextWrapping="WrapWithOverflow"></TextBlock> 
        </StackPanel> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
      <ListBox.ItemsPanel> 
       <ItemsPanelTemplate> 
        <VirtualizingStackPanel Background="Black" CanHorizontallyScroll="True" CanVerticallyScroll="False" FlowDirection="LeftToRight" Margin="0" Orientation="Horizontal" Width="1010" Height="275"></VirtualizingStackPanel> 
       </ItemsPanelTemplate> 
      </ListBox.ItemsPanel> 
     </ListBox>`$ 

autres informations pertinentes

   CurrentItems = (from offerCatType in offerRes.OfferCategory 
             where offerCatType.type == Type 
             from offers in offerCatType.Offer 
             where new  DateTime(Convert.ToDateTime(offers.startDate).Year, 
    Convert.ToDateTime(offers.startDate).Month, 1) <= MonthYear && Convert.ToDateTime(offers.endDate) >= MonthYear 
             select new Offer 
             { 
              Name = offers.name, 
              Description = offers.description, 
              Date = String.Format("{0:dd/MM/yyyy}",  Convert.ToDateTime(offers.startDate)) + " to " + String.Format("{0:dd/MM/yyyy}", Convert.ToDateTime(offers.endDate)), 
              ClickThruUrl = offers.ChannelInfo.refClickThroughLink, 
              ReferenceID = offers.ChannelInfo.refId, 
              Image = offers.ChannelInfo.refLink 
             } 
         ); 



     listBox1.ItemsSource = CurrentItems; 
     protected void ListBox_MouseLeftButtonDown(object sender, RoutedEventArgs e) 
     {} 

Est-il possible une partie de mon style pourrait souffler cet événement? Je l'ai fait travailler plus tôt aujourd'hui, puis réparait quelques éléments de style, puis, le code de clic a cessé de fonctionner.

Répondre

0

Définissez la propriété IsHitTestVisible sur true au lieu de false pour la zone de liste et vous obtiendrez des événements de souris.

+0

Cela ne fonctionne pas – user1034912

Questions connexes