tCo*_*Coe 9 c# wpf checkbox xaml listbox
我遇到了设计问题,我知道必须有一种方法可以使它工作.我在这里尝试了解决方案:在WPF ListView中部分显示项目的烦人自动滚动
但是它们对我没有用,因为我不允许在代码隐藏中工作.我有一个来自wpf的项目列表ListBox.像这样:
当我尝试选择第CheckBox5行时,Window它的中心但不检查它.经过进一步测试后,我发现CheckBox只要项目的下边框不在视图中,就不会选择它.
这是ListBox和它的xaml Style:
<ListBox Grid.Column="0" Grid.Row="1" Name="RequestCheckoutV"
ItemsSource="{Binding Path=CheckoutVM, Mode=TwoWay, IsAsync=True}"
SelectedItem="{Binding Path=SelectedPermit}"
BorderThickness="0"
KeyboardNavigation.TabNavigation="Continue">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="KeyboardNavigation.IsTabStop" Value="False" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Control.HorizontalContentAlignment" Value="Center"/>
<Setter Property="Control.VerticalContentAlignment" Value="Top"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}" >
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能选中复选框而不只是居中?任何帮助表示赞赏.
因此,通过向ClickMode属性添加"Press"的规范,CheckBox通过ClickMode="Press"您告诉该对象基本上忽略了由列表项模板劫持的事件.现在它将接受它的命中区域中的第一个事件而不是列表项,因为它的默认值是"Release".干杯:)