private void ConnectButton_Click(object sender, RoutedEventArgs e) { if (this.DataContext == null) { this.DataContext = new ChatObjectModel.ObjectModel(); } ObjectModel objModel = (ObjectModel)this.DataContext; objModel.Connect(this.UserName.Text); objModel.ResponseReceived += ChatReceived; objModel.PropertyChanged += objModel_PropertyChanged; this.ConnectButton.IsEnabled = false; this.UserName.IsEnabled = false; }