Reputation: 431
i have a list view like this .
<ListView x:Name="Source_List"
ItemsSource="{Binding Lines}"
IsSynchronizedWithCurrentItem="True"
SelectionChanged="Source_List_SelectionChanged">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment"
Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Line"
Width="50"
DisplayMemberBinding="{Binding LineNumber}" />
<GridViewColumn Header="Start Time"
Width="100"
DisplayMemberBinding="{Binding StartTime , Converter={StaticResource LineTimeToString}}" />
<GridViewColumn Header="End Time"
Width="100"
DisplayMemberBinding="{Binding EndTime ,Converter={StaticResource LineTimeToString}}" />
<GridViewColumn Header="Text"
Width="500">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=Context ,Mode=TwoWay}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Original Text"
DisplayMemberBinding="{Binding Context ,Mode=OneTime}" />
</GridView>
</ListView.View>
</ListView>
I want to access the text box inside the selected items as a textbox.(in code behind ) how can i do this?
i used this article by beth massi.
Upvotes: 0
Views: 859
Reputation: 341
you can acces to textbox ui element (if your texblock is clicked)
TextBlock content = ((FrameworkElement)e.OriginalSource) as TextBlock;
else if your texblock is inside a grid use
Grid c = ((FrameworkElement)e.OriginalSource) as Grid;
and search for the grid(c) children.
Upvotes: 1
Reputation: 925
Because you are using IsSynchronizedWithCurrentItem="True"
you should be able to access the current item of your list 'Lines'
. Your text box is bound to Context so I would assume in your view model you would be able to call 'Lines.CurrentItem.Context'
Upvotes: 0