I have stack panel inside DataGrid.RowDetailsTemplate. In the stack panel I have text Box and button. The function of the button in the c# code behind tried to use the value from the text box but there is an error :
"The name 'toCheck' does not exist in the current context".
What can I do so that I could use the value from the text box?
xaml :
<DataGrid.RowDetailsTemplate >
<DataTemplate >
<Border>
<StackPanel>
<Label Name="headLine" Content="what do you want to change:" HorizontalAlignment="Left" Height="40" Margin="10,50,0,0" VerticalAlignment="Top" Width="170"/>
<TextBox Name="toCheck" HorizontalAlignment="Left" Text="{Binding Name}" Height="23" Margin="34,0,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="130"/>
<Button Name="check" Content="Check" HorizontalAlignment="Left" Margin="105,50,0,0" VerticalAlignment="Top" Width="75" Click="check_Click"/>
</StackPanel>
</Border>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
c# behind :
public partial class window1 : UserControl
{
public window1 ()
{
InitializeComponent();
}
private void check_Click(object sender, RoutedEventArgs e)
{
string needCheck = toCheck.Text;
if (needCheck == "abc")
{
MessageBox.Show("its abc");
}
}
thank you all.