I have a ListView
with a bound ItemsSource
and a GridViewColumns
to display a given items property. Here is a snippet of the important bits:
<ListView Name="listView1" ItemsSource="{Binding Path=listItemCollection}" DataContext="{Binding ListItem}">
<ListView.View>
<GridView x:Name="gridViewMain">
<GridViewColumn x:Name="listViewItemNumberColumn" Width="50">
<GridViewColumnHeader>#</GridViewColumnHeader>
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock x:Name="idTextBlock" KeyboardNavigation.IsTabStop="False" HorizontalAlignment="Center" Text="{Binding Path=Id}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="listViewItemNameColumn" Width="500">
<GridViewColumnHeader>Name</GridViewColumnHeader>
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox x:Name="nameTextBox" TextChanged="nameTextBox_TextChanged" Text="{Binding Path=ItemName, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
...
I want to be able to focus on a specific field/textbox within a user-selected ListViewItem
. I am able to find the ListViewItem
from a given index using this code:
listView1.ItemContainerGenerator.ContainerFromIndex(i);
All is well and good so far. That is until I want to actually access the content within the ListViewItem
. Instead of ListViewItem.Content
returning a group of controls which I am expecting, it returns my custom class ListItem
. Here is a snippet of what that class looks like:
public class ListItem : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
public TextBlock idTextBlock;
public GridView gridViewMain;
public bool Selected { get; set; }
public string ItemName { get; set; }
I am completely lost in how I would for example focus onto the nameTextBox
text box control within a ListViewItem.
Is it possible to somehow link the controls such as the nameTextBox
and idTextBlock
to my custom ListItem
class?