Witam Państwa,
jestem początkującym programistą C# na WPF i mam raczej banalny problem.
Przykład:
W nowym projekcie na gridzie dodaje dwa pola tekstowe(TextBox) o nazwach txt_input i txt_output
Do pola txt_input przypisuje handlera TextChanged.
Każda zmiana tekstu ma powodować wyświetlenie się tego tekstu w drugim polu txt_output.
Cały kod C# poniżej:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void txt_input_TextChanged(object sender, TextChangedEventArgs e)
{
this.txt_output.Text = this.txt_input.Text;
}
}
}
Wyskakuj mi błąd w tej linii this.txt_output.Text = this.txt_input.Text; o treści:
A first chance exception of type 'System.NullReferenceException' occurred in WpfApplication1.exe
An exception of type 'System.NullReferenceException' occurred in WpfApplication1.exe but was not handled in user code
Additional information: Odwołanie do obiektu nie zostało ustawione na wystąpienie obiektu.
Proszę o pomoc. W Windows Form nie miałem takiego problemu z przypisaniem wartości do innego pola tekstowego
Na logikę nie widzę w kodzie błędu.