PreviewMouseLeftButtonDown未触发 [英] PreviewMouseLeftButtonDown not firing
本文介绍了PreviewMouseLeftButtonDown未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的ListBox XAML
`< ListBox Name =listBox1Margin =0Width =1010Height =275BorderThickness =0BorderBrush ={ x:Null}Cursor =ArrowHorizontalAlignment =CenterVerticalAlignment =TopSelectionMode =SingleFontFamily =DINScrollViewer.HorizontalScrollBarVisibility =HiddenFocusable =FalseIsHitTestVisible =FalseIsTextSearchEnabled = False>`
< ListBox.ItemContainerStyle>
< Style TargetType ={x:Type ListBoxItem}>
< EventSetter Event =PreviewMouseLeftButtonDownHandler =ListBox_MouseLeftButtonDown>< / EventSetter>
< / Style>
< /ListBox.ItemContainerStyle>
< ListBox.ItemTemplate>
< DataTemplate DataType ={x:Type local:Offer}>
< StackPanel Margin =0Width =200Height =275Background =BlackName =sp>
< Image Source ={Binding Image}Width =200Height =131Margin =0>< / Image>
< TextBlock Padding =5Background =BlackText ={Binding Name}Foreground =WhiteFontFamily =DIN mediumFontWeight =BoldFontSize =16Width =200 Margin =0>< / TextBlock>
< TextBlock Padding =5,0,5,0Background =BlackText ={Binding Date}Foreground =WhiteFontFamily =DIN mediumFontWeight =BoldFontSize = 14Width =200Margin =0>< / TextBlock>
< TextBlock Padding =5Background =BlackText ={Binding Description}Foreground =WhiteFontFamily =DIN lightFontSize =16Width =200Margin =0 TextWrapping =WrapWithOverflow>< / TextBlock>
< / StackPanel>
< / DataTemplate>
< /ListBox.ItemTemplate>
< ListBox.ItemsPanel>
< ItemsPanelTemplate>
< VirtualizingStackPanel Background =BlackCanHorizontallyScroll =TrueCanVerticallyScroll =FalseFlowDirection =LeftToRightMargin =0Orientation =HorizontalWidth =1010Height =275>< ; / VirtualizingStackPanel>
< / ItemsPanelTemplate>
< /ListBox.ItemsPanel>
< / ListBox>`$
其他相关信息
CurrentItems =(from offerCatType in offerRes.OfferCategory
where offerCatType.type ==键入
从offerCatType.Offer中的优惠
其中新的DateTime(Convert.ToDateTime(offers.startDate).Year,
Convert.ToDateTime(offers.startDate).Month,1)< = MonthYear&&&Convert.ToDateTime(offers.endDate)> ; = MonthYear
select new Offer
{
Name = offers.name,
描述= Offers.description,
Date = String.Format({0:dd / MM / yyyy},Convert.ToDateTime(offers.startDate))+to+ String.Form at({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)
{}
是可能我的一些风格可能会吹走这个事件?我今天早些时候工作,然后修理了一些更多的造型项目,然后点击代码停止工作。
解决方案
为列表框设置IsHitTestVisible属性为true而不是false,您将获得鼠标事件。
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.
解决方案
Set the IsHitTestVisible property to true instead of false for the listbox and you will get mouse events.
这篇关于PreviewMouseLeftButtonDown未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文