2010-06-23 71 views
0

我有一个ListBox,IEnumerable是数据源。当单击ListBoxItem时,我想访问该对象,以便我可以抓取一些数据并显示另一个窗口。PreviewMouseLeftButtonDown not firing

这里是我的列表框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>`$ 

其他相关信息

   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) 
     {} 

是否有可能我的一些造型都刮不走这个事件的?我今天早些时候开始工作,然后修复了更多样式的项目,然后点击代码停止工作。

回答

0

为列表框设置IsHitTestVisible属性为true而不是false,您将获得鼠标事件。

+0

这不工作 – user1034912 2017-02-22 10:56:58