TextHandler handler = new TextHandler(); // This is where text storing happens and adding public MainWindow() { InitializeComponent(); handler.CreateJsonFile(); DisplayToListBox(); // Below this adds Commandbinding which activates user presses copys text from listbox CommandBinding cb = new CommandBinding(ApplicationCommands.Copy, CopyCmdExecuted, CopyCmdCanExecute); listBox1.CommandBindings.Add(cb); Application.Current.MainWindow.Closing += new CancelEventHandler(MainWindow_Closing); }