I have a ListBox, an IEnumerable is the data source. When a ListBoxItem is clicked, I want access to that object so I can grab some data and show another window.
Here is my 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>`$
other pertinent info
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)
{}
Is it possible some of my styling could blow away this event? I had it working earlier today, then was fixing a couple more styling items, then, the click code stopped working.