tCoe tCoe - 1 year ago 89
C# Question

Selecting a partially displayed WPF checkbox

so I am having a design problem and I know there has to be a way to make it work. I tried the solutions here: Annoying auto scroll of partially displayed items in WPF ListView
But they didnt work for me because I am not allowed to work in the code-behind.
I have a list of items from a wpf listbox. like this:

Listbox picture

when I try to select the checkbox in line 5, the window centers on it but does not check it. After further testing, I found that it will not select the checkbox as long as the bottom border of the item is not in view.

here is the xaml for the listbox:

<ListBox Margin="4 8 " Grid.Row="1" ItemsSource="{Binding Path=CheckoutVM,Mode=TwoWay,IsAsync=True}"
SelectedItem="{Binding Path=SelectedPermit}" Grid.Column="0" BorderThickness="0"
KeyboardNavigation.TabNavigation="Continue" Name="RequestCheckoutV" >

and here is the style:

<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">
<ControlTemplate TargetType="{x:Type ListBoxItem}" >
<ContentPresenter />

What can I do to make this select the checkbox instead of just centering it?
Any help is appreciated.

Answer Source

So by adding the specification of "Press" to ClickMode property to CheckBox via ClickMode="Press" you're telling that object to basically ignore the event otherwise hijacked by the list item template. Now it will accept the first event in it's hit area for itself instead of the list item. Cheers :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download