Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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


XML
<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


VB
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
Updated 8-Mar-13 1:00am
v5
Comments
Sajith Sageer 8-Aug-18 4:37am    
People coming here in the future, see the below link. It will probably help you.

https://social.technet.microsoft.com/wiki/contents/articles/25152.wpf-how-to-tab-between-items-in-a-listbox.aspx

Basically you have to set KeyboardNavigation.TabNavigation="Local" on your ListView and set IsTabStop to false on your ListViewItem.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900