Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF checkbox ListView Keyboard , +
I have listview with Checkbox Items that are not HardCoded in XAML i load them during run time,
I have two scenarios
***- Listview items Hardcoded

- ListView items loaded Through Itemsource***

ListviewItems with Checkbox HardCoded

*
> Apple , Apple1 , Ball, Bottom, Mango, Fruit, Ear, Items, etc..
*
In this scenario, If i Press A first item that starts with letter **A** will get Focus and again Pressing A Focus set to next Item that starts with letter **A**, if it reaches the last item starts with letter **A** then again if i press A it has to goto the first item that has starting letter **A**.
This works perfect when i do hardcode the **ListViewItem**
But Unable to Select the CheckBox Through Keyboard.
 

ListviewItems with Checkbox Loaded Dynamically

If i load them through **ItemsSource** within **DataTemplate** i cannot acheive the above feature andalso unable to select Checkbox using Keyboard.
 

Listview items to be loaded

 <listview name="LV" itemssource="{Binding Responses}" borderthickness="2" tag="{Binding GUID}" removed="Khaki" margin="5">
            <listview.itemtemplate>
                <datatemplate>
                    <stackpanel x:name="Sp1" orientation="Vertical" height="Auto" datacontext="{Binding Path=.}" xmlns:x="#unknown">
                        <!--<Label x:Name="lbl"  BorderBrush="Black" BorderThickness="2" Margin=" 0,5,0,5"  
                              Height="{Binding ActualHeight}"  Background="#336699" HorizontalAlignment="Stretch"   Content="{Binding Path = ShowHeader}"  Visibility="{Binding Path= ShowHeader, 
                               Converter={StaticResource Header}}" Padding="0" FontStretch="UltraCondensed"  FontWeight="Bold" Foreground="WhiteSmoke"  FontSize="18" FontFamily="Sego">
                    
                    IsCheckedReal="{Binding Path=Checked, Mode=TwoWay}"
                        </Label>-->
                    <bc:checkboxextended checked="McCheckBox_Checked" margin="5" unchecked="McCheckBox_Unchecked" ischeckedreal="{Binding Path=Checked, RelativeSource={RelativeSource FindAncestor,  AncestorType={x:Type ListViewItem}}}" fontfamily="Verdana" fontsize="12" xmlns:bc="#unknown">
                            <checkbox.content>
                                <binding path="DisplayText" />
                            </checkbox.content>
                        </bc:checkboxextended>
                    </stackpanel>
                </datatemplate>
            </listview.itemtemplate>
        </listview>                            
                        


 
CheckboxExtended Codebehind
 
 Public Class CheckBoxExtended
        Inherits CheckBox
     Public Property IsCheckedReal() As System.Nullable(Of Boolean)
            Get
                Return CType(GetValue(IsCheckedRealProperty), System.Nullable(Of Boolean))
            End Get
            Set(ByVal value As System.Nullable(Of Boolean))
                SetValue(IsCheckedRealProperty, value)
            End Set
        End Property
    
             Public Shared ReadOnly IsCheckedRealProperty As DependencyProperty = DependencyProperty.Register("IsCheckedReal", GetType(System.Nullable(Of Boolean)), GetType(CheckBoxExtended), New FrameworkPropertyMetadata(False, FrameworkPropertyMetadataOptions.Journal Or FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, AddressOf IsCheckedRealChanged))
    
        Public Shared Sub IsCheckedRealChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
            m_bIsChanging = True
            DirectCast(d, CheckBoxExtended).IsChecked = CBool(e.NewValue)
            m_bIsChanging = False
        End Sub
   ' Using a DependencyProperty as the backing store for IsCheckedReal. This enables animation, styling, binding, etc...
    End Class
1. I need to travel the items by pressing the starting letter thrugh Keyboard(This is default feature of Listview,Its not working when i do it within datatemplate)
2. Need to check and Uncheck the checkboxItems
Posted 8-Mar-13 1:49am
Edited 8-Mar-13 2:00am
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 565
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 8 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100