void DisCommand(object sender, RoutedEventArgs e) { try { CanCD = false; Connect_btn.IsEnabled = false; cl.ClientDis(); cl.reply("Disconnected"); Connect_btn.Content = "Connect"; binding1.Executed += new ExecutedRoutedEventHandler(ConnectCommand); Connect_btn.IsEnabled = true; CanCD = true; CanSend = false; cl = null; } catch { cl.reply("You are already disconnected"); Connect_btn.Content = "Connect"; Connect_btn.IsEnabled = true; CanSend = false; CanCD = true; cl = null; return; } }