// methods public void InitChat() { //bindingin kautta linkitetään setit libChannels.ItemsSource = ChatWindowLogic.HaeKanavat(); timer = new DispatcherTimer(); timer.Tick += new EventHandler(ViestiHaku); timer.Interval = TimeSpan.FromSeconds(chatRefresh); }
//Events private void createChannel_KeyDown(object sender, KeyEventArgs e) { try { if (e.Key == Key.Return) { TextBox kanava = new TextBox(); PasswordBox passu = new PasswordBox(); foreach (object child in txbChatWindow.Children) // käydään txbChatWindow läpi ja asetetaan halutut arvot { if (child is PasswordBox) // jos objecti on passwordbox castataan sen arvot muuttujaan { passu = (PasswordBox)child; if (passu.Password == null) { throw new Exception("Please enter password"); } } else if (child is TextBox) // jos objecti on textbox castataan se muuttujaan { kanava = (TextBox)child; if (kanava.Text == null) { throw new Exception("Please enter channel name"); } } } txbChatWindow.Children.Clear(); ChatWindowLogic.LuoKanava(kanava.Text, passu.Password); libChannels.ItemsSource = ChatWindowLogic.HaeKanavat(); passu = null; kanava = null; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }