0

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.

1
  • 1
    how do you want to access the textbox? in code or in XAML? you should provide more info on that, such as your purpose of doing so... Commented Oct 2, 2015 at 9:28

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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'

3 Comments

i want to access that text box as TextBox object like normal textbox. Context (in my Line Object is a string) . pleas help me
for what purpose exactly? because you shouldn't couple your view with your view model however in the xaml.cs if you gave your textbox a name or an x:name then you would be able to access it there.
Ok . Thanks for answer .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.