即使有
Background="{x:Null}"
列表框会吞噬所有鼠标事件。您可以通过附加MouseMove事件处理程序来验证这一点。这肯定是由于列表框中的Border或ScrollViewer元素造成的
Template
.
因此,您必须修改模板,例如
<ListBox ItemsSource="{Binding ListSource}" Background="{x:Null}">
<ListBox.Template>
<ControlTemplate TargetType="ListBox">
<ItemsPresenter/>
</ControlTemplate>
</ListBox.Template>
...
</ListBox>
或者你只是使用
ItemsControl
而不是列表框:
<Grid>
<Image Source="{Binding ImageSource}"
ToolTipService.ToolTip="{Binding ImageToolTip}" />
<ItemsControl ItemsSource="{Binding ListSource}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding Left}" />
<Setter Property="Canvas.Top" Value="{Binding Top}" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Ellipse Width="10" Height="10" Fill="White"
ToolTipService.ToolTip="{Binding Name}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>