2011-09-18 6 views
17

ठीक है मेरे पास एक सूची दृश्य है जिसमें 2 ग्रिड व्यू कॉलम एक नंबर प्रदर्शित कर रहे हैं और एक टेक्स्टबॉक्स है मेरी समस्या यह है कि मैं ग्रिड व्यू कॉलम में मौजूद सभी टेक्स्टबॉक्स के माध्यम से टैब करने में सक्षम होना चाहता हूं। अटैचमेंट प्रॉपर्टी कीबोर्ड नविगेशन के साथ। टैबनेविगेशन मैं लगभग वही हासिल करता हूं जो मैं चाहता हूं।
क्या मैं प्राप्त है:
पहला टैब - पूरे पहली ListViewItem ध्यान केंद्रित
दूसरे टैब - पहला पाठ बॉक्स ध्यान केंद्रित
तीसरे टैब - पूरे दूसरी ListViewItem ध्यान केंद्रित
चौथा टैब - दूसरे पाठ बॉक्स ध्यान केंद्रित
किसी सूची दृश्य में टेक्स्टबॉक्स के माध्यम से टैब कैसे करें

जो मैं चाहता है
पहला टैब - पहला पाठ बॉक्स ध्यान केंद्रित
दूसरे टैब - दूसरे पाठ बॉक्स ध्यान केंद्रित

<ListView KeyboardNavigation.TabNavigation="Continue" Name="TheLabelListView" > 
          <ListView.ItemContainerStyle > 
            <EventSetter Event="Selected" Handler="ItemSelected" /></Style> 
          </ListView.ItemContainerStyle> 
          <ListView.View> 
           <GridView x:Name="GridViewSmall" > 
            <GridViewColumn Header="#" Width="20" DisplayMemberBinding="{Binding SelectorIndexNumber}" /> 
            <GridViewColumn Header="Selector" Width="175"> 
             <GridViewColumn.CellTemplate> 
              <DataTemplate> 
               <TextBox Name="SelectorTextBox" Text="{Binding SelectorName}" />              
              </DataTemplate> 
             </GridViewColumn.CellTemplate> 
            </GridViewColumn> 
           </GridView> 
          </ListView.View> 
         </ListView> 

यह कोड मुझे एचबी द्वारा दिया गया था। । यह तब होता है जब कोई ListViewÍtem चुना जाता है और टेक्स्टबॉक्स ढूंढता है और इसे केंद्रित करता है। किसी भी तरह से यह तब भी टेक्स्टबॉक्स का चयन नहीं करता है जब भी यह विधि निष्पादित की जाती है जब बूल TextBoxgotFocus हमेशा सत्य होता है।

private void ItemSelected(object sender, RoutedEventArgs e) 
    { 
     var item = sender as ListViewItem; 
     TextBox h = (FindNamedChild(item, "SelectorTextBox") as TextBox); 
     bool TextBoxgotFocus = h.Focus(); 
    } 

    public static object FindNamedChild(DependencyObject container, string name) 
    { 
     if (container is FrameworkElement) 
     { 
      if ((container as FrameworkElement).Name == name) return container; 
     } 
     var ccount = VisualTreeHelper.GetChildrenCount(container); 
     for (int i = 0; i < ccount; i++) 
     { 
      var child = VisualTreeHelper.GetChild(container, i); 
      var target = FindNamedChild(child, name); 
      if (target != null) 
      { 
       return target; 
      } 
     } 
     return null; 
    } 

उत्तर

27

समस्या यह है कि सूची में प्रत्येक आइटम के लिए, आपके पास दो टैब स्टॉप हैं: आइटम स्वयं और टेक्स्ट बॉक्स। आप वस्तुओं के लिए KeyboardNavigation.IsTabStopfalse पर सेट करना चाहते हैं। बस इसे अपने आइटम की शैली में सेट करें।

<ListView KeyboardNavigation.TabNavigation="Continue" Name="TheLabelListView"> 
    <ListView.ItemContainerStyle> 
     <Style> 
      <Setter Property="KeyboardNavigation.IsTabStop" Value="False" /> 
     </Style> 
    </ListView.ItemContainerStyle> 

    <!-- etc... --> 
</ListView> 
+0

धन्यवाद। यह ठीक है –

+0

मुझे हाल ही में एक ही मुद्दे का सामना करना पड़ा। लेकिन आपके जवाब में मदद नहीं मिली। मुझे पता चला है कि सूची कोई टेक्स्ट बॉक्स वाले आइटम देखें (उनमें कोई टैबस्टॉप नहीं) पूरी सूची क्रश करें टैब नेविगेशन देखें। दूसरे शब्दों में eveything केवल तभी ठीक है जब प्रत्येक सूची आइटम में कम से कम एक टैबस्टॉप होता है और उस स्थिति में - हाँ - आपको आइटम कंटेनर के लिए इसे अच्छी तरह से करने के लिए बस कोई टैबस्टॉप सेट करने की आवश्यकता नहीं है। लेकिन क्या होगा यदि कुछ आइटम हेडर की तरह काम करते हैं? कृपया मदद करे। – mjollneer

संबंधित मुद्दे