我遇到了设计问题,我知道必须有一种方法可以让它发挥作用。我在这里尝试了解决方案:Annoying auto scroll of partially displayed items in WPF ListView
但他们没有为我工作,因为我不被允许在代码隐藏工作。
我有一个来自wpf ListBox
的项目列表。像这样:
当我尝试在第5行中选择CheckBox
时,Window
会以CheckBox
为中心,但不会检查它。经过进一步测试后,我发现只要项目的下边框不在视图中,它就不会选择ListBox
。
以下是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>
:
deep_print
我该怎么做才能选中复选框而不只是居中? 任何帮助表示赞赏。
答案 0 :(得分:5)
因此,通过ClickMode
向CheckBox
属性添加“{”的规范到ClickMode="Press"
,您告诉该对象基本上忽略了列表项模板劫持的事件。现在它将接受它的命中区域中的第一个事件而不是列表项,因为它的默认值是“Release”。干杯:)
答案 1 :(得分:3)
尝试添加到.ItemContainerStyle
:
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="IsSelected" Value="True"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
这将有效地关注您在那里点击的任何内容。