我有一个问题ListBoxItem.我试图让所有的控制在ListBoxItem选择它作为很好,所以点击一个TextBox,Label等会选择ListBoxItem.到目前为止很简单.
我也在更改ListBoxItem模板以更改选择可视化,从突出显示背景到仅绘制边框.也很简单.
这两者的结合,然而,似乎导致有一些很刺激的问题MouseDown和PreviewMouseDown,特别是在我的情况下,关于LabelS IN一个Grid,其中一个创建一个"空白"所占据Grid的空间.
使用snoop,我可以看到PreviewMouseDown事件在ScrollViewer内部停止ListBox,而不是一直到达ListBoxItem.

XAML:
<Window x:Class="ListBoxClickThroughTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Width="525"
Height="350">
<Grid>
<ListBox ItemsSource="{Binding Items}"
SelectionMode="Single">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Label Name="VerySuperLongLabel"
Grid.Row="0"
Grid.Column="0"
HorizontalAlignment="Left"
Content="VerySuperLongLabel"
Padding="0" />
<TextBox Name="Textbox1"
Grid.Row="0"
Grid.Column="1"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Right"
Text="Textbox1 …Run Code Online (Sandbox Code Playgroud)