Get the Value of a Textbox within a Datagrid RRS feed

  • Question

  •  <ItemsControl x:Name="icContextProperties" IsTabStop="False" Height="Auto" Width="Auto" HorizontalAlignment="Left" VerticalAlignment="Top">
                        <DataTemplate x:Name ="DataTemplateCheckBoxes">
                                            <StackPanel Orientation="Horizontal" x:Name="PropertyContextStackPanel">
                        <TextBlock Text="{Binding PropertyName}" Margin="0,0,50,0" x:Name="PropertyContextLabel" />
                    <TextBox Height="21.167" Width="215.68" FontSize="12" Text="" LostFocus="PropertyContextUserInput_LostFocus" x:Name="PropertyContextUserInput"/>


    Now I can get the value of the TextBox  "PropertyContextUserInput" that is filled in using the LostFocus eventhandler.

    How do I know the value of the TextBlock "PropertyContextLabel" that's in the same StackPanel? 


    thank you in advance 

    Monday, May 5, 2008 5:06 PM


  • void  PropertyContextUserInput_LostFocus(sender, e)


        TextBox t = sender as TextBox;

    //    t.Text  is the value user filled in the textbox

       MyDataObject d = t.DataContext as MyDataObject;  // This is the Data bound to that row. Now you can access all the fields on of your DataObject

      // d.PropertyName should be the value in the TextBlock on that same row.

    Monday, May 5, 2008 5:26 PM