I just want to save a normal TextBox widget to another variable, so as soon as the error occurs
System.NullReferenceException: “The object reference was not set to an object instance.”
you can even see that everything has a value and none of these variables is null
private void AddMessageButton_Click(object sender, RoutedEventArgs e)
{
Schools_ViewModel viewModel = new Schools_ViewModel();
string subject = SubjectTextBox.Text.Trim();
string messageText = MessageTextBox.Text.Trim();
int? userId = UserSession.Instance.CurrentUser.UserId;
int? teacherId = viewModel.selectedTeacher.TeacherId;
int? fileId = null;
viewModel.AddMessage(userId, teacherId, fileId, subject, messageText);
SubjectTextBox.Clear();
MessageTextBox.Clear();
}
and here is the view
<StackPanel Grid.Row="1">
<Border BorderBrush="#b9bbbe" BorderThickness="1" Margin="5">
<TextBox x:Name="SubjectTextBox" Text="Enter Subject" BorderThickness="0"
Background="Transparent" Foreground="#ffffff" Height="30" AcceptsReturn="True"
TextWrapping="Wrap"/>
</Border>
<Border BorderThickness="0, 1, 0, 1" BorderBrush="#b9bbbe" Margin="5, 0, 5, 0">
<TextBox x:Name="MessageTextBox" Text="Enter Message" Margin="5" BorderThickness="0"
Background="Transparent" Foreground="#ffffff" Height="150" AcceptsReturn="True"
TextWrapping="Wrap"/>
</Border>
<TextBlock Name="fileInfoTextBlock" Foreground="#ffffff" Margin="5" FontSize="13"/>
</StackPanel>
idk what to try next
New contributor
susmi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.