void TestWindow_AddMessageEvent(object sender, string e) { Dispatcher.Invoke(() => { InfoListBox.Items.Add(e); InfoListBox.ScrollIntoView(e); }); }
private void ChangeProgrammes() { if (ChannelListBox.SelectedItem == null) { return; } InfoListBox.Items.Clear(); ListBoxItem listItem = ChannelListBox.SelectedItem as ListBoxItem; Channel channel = listItem.Tag as Channel; int day = -1; int selectedIndex = -1; foreach (Programme programme in channel.Programmes) { if (day != programme.Start.Day) { InfoListBox.Items.Add(new ListBoxItem { Content = $"{programme.Start:dd.MM.yyyy}", Background = new SolidColorBrush(Color.FromRgb(245, 245, 245)), Foreground = Brushes.Black, IsEnabled = false }); } if (DateTime.Now > programme.Start && DateTime.Now < programme.End) { selectedIndex = InfoListBox.Items.Count; InfoListBox.Items.Add(new ListBoxItem { Content = programme, ToolTip = programme.Title, Tag = programme, IsSelected = true, FontWeight = FontWeight.FromOpenTypeWeight(700) }); } else { InfoListBox.Items.Add(new ListBoxItem { Content = programme, ToolTip = programme.Title, Tag = programme }); } day = programme.Start.Day; } if (selectedIndex > -1) { var item = InfoListBox.Items[selectedIndex]; InfoListBox.ScrollIntoView(InfoListBox.Items[InfoListBox.Items.Count - 1]); UpdateLayout(); InfoListBox.ScrollIntoView(item); } }