2010-10-11 3 views
1

У меня есть listview вот так и хотел бы получить доступ к текстовому поле ВЫБРАННЫЙ ПУНКТ в стороне?Контроль доступа в ListView в WPF

lsitview.blah.blah.findTheTextBox ("blah"). Name = "good!";

Как я могу это сделать? Благодаря

<ListView Name="listview"> 
    <ListView.View> 
    <GridView> 
     <GridViewColumn> 
     <GridViewColumn.CellTemplate> 
      <DataTemplate> 
      <TextBox Text="{Binding}"/> 
      </DataTemplate> 
     </GridViewColumn.CellTemplate> 
     </GridViewColumn> 
    </GridView> 
    </ListView.View> 
</ListView> 
+1

что вы пытаетесь достичь? Ответ будет зависеть от того, что вы хотите сделать. –

+0

@ Кен Хендерсон Я хочу прочитать текст из «TextBox» – Towhid

ответ

2

Ничего, я figoure это:

SequenceItem _item = dgSequence.SelectedItem as SequenceItem; 
      if (_item != null) 
       _item.IsReadOnly = false; 

      ListViewItem _lstItem = dgSequence.GetCurrentListItem(); 
      if (_lstItem != null) 
      { 
       TextBox _txt = _lstItem.GetDescendantByType<TextBox>(); 
       if (_txt != null) 
       { 
        _txt.GetBindingExpression(TextBox.IsReadOnlyProperty).UpdateTarget(); 
        _txt.Focus(); 
        _txt.SelectAll(); 
       } 
      } 

     public static T GetDescendantByType<T>(this Visual element) where T : Visual 
     { 

      if (element == null) return null; 

      if (element is T) return (T)element; 

      T foundElement = null; 

      if (element is FrameworkElement) 

       (element as FrameworkElement).ApplyTemplate(); 

      for (int i = 0; 

       i < VisualTreeHelper.GetChildrenCount(element); i++) 
      { 

       Visual visual = VisualTreeHelper.GetChild(element, i) as Visual; 

       foundElement = GetDescendantByType<T>(visual); 

       if (foundElement != null) 

        break; 

      } 

      return foundElement; 

     } 

     public static ListViewItem GetCurrentListItem(this ListView lstvw) 
     { 
      if (lstvw.SelectedIndex < 0) 
       return null; 
      ListViewItem _lstItem = lstvw.ItemContainerGenerator.ContainerFromIndex(lstvw.SelectedIndex) as ListViewItem; 
      return _lstItem; 
     } 
Смежные вопросы