PreviewMouseLeftButtonDown не стреляет - PullRequest
0 голосов
/ 23 июня 2010

У меня есть ListBox, IEnumerable является источником данных. Когда щелкает элемент ListBoxItem, я хочу получить доступ к этому объекту, чтобы я мог получить некоторые данные и показать другое окно.

Вот мой 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>`$

другая соответствующая информация

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

Возможно ли, что некоторые из моих стилей могут сдуть это событие? Я работал сегодня раньше, потом исправлял еще пару элементов стиля, затем код щелчка перестал работать.

1 Ответ

0 голосов
/ 23 июня 2010

Установите для свойства IsHitTestVisible значение true вместо false для списка, и вы получите события мыши.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...