private void UpdatetItemByPerson(Person person) { if (!excludedIds.Contains(person.Cardnr)) { try { Brush red = new SolidColorBrush(Color.FromArgb(255, 255, 75, 75)); Brush green = new SolidColorBrush(Color.FromArgb(255, 75, 255, 75)); Brush yellow = new SolidColorBrush(Color.FromArgb(255, 255, 255, 75)); Dictionary <string, string> icons = new Dictionary <string, string> { { "Schule", "🎓" }, { "Krankheit", "🚑" }, { "Urlaub", "✈" }, { "Elternzeit", "👨👩👦" }, }; string absenceReason = person.AbsenceReason != null && person.AbsenceReason.Length > 0 ? person.AbsenceReason : person.Dayprog != null && person.Dayprog == "Schule" ? "Schule" : ""; string additionalInfos = HasBirthday(person.getBirthday()) ? "🎂" : ""; absenceReason = absenceReason.Length > 0 ? icons[absenceReason] : ""; ListViewItem listItem = (ListViewItem)MainListBox.FindName(person.Cardnr.ToString()); if (listItem == null) { ListViewItem item = new ListViewItem { Name = person.Cardnr.ToString(), HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center, VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch, Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)), Background = absenceReason.Length <= 0 ? person.Present ? green : red : yellow, Content = String.Format("{0} {1} {2}", absenceReason, additionalInfos, person.Name) }; MainListBox.Items.Add(item); } else { listItem.Background = absenceReason.Length <= 0 ? person.Present ? green : red : yellow; } } catch (Exception e) { string error = e.Message; } } }
/// <summary> /// 写入日志 /// </summary> /// <param name="mes"></param> private void Message(string mes) { if (MainListBox.InvokeRequired) { MainListBox.Invoke(new UpdateUiDelegate(Message), new object[] { mes }); } else { if (MainListBox.Items.Count > 300) { MainListBox.Items.RemoveAt(0); } MainListBox.Items.Add(mes); MainListBox.SelectedIndex = MainListBox.Items.Count - 1; } }
void _vm_RitInfoAvailable(object sender, EventArgs e) { try { //Scroll to current station if (_vm != null && _vm.RitStops != null) { var currentItem = _vm.RitStops.Where(x => x.IsCurrent).FirstOrDefault(); if (currentItem != null) { MainListBox.ScrollTo(currentItem); } } } catch { //Ignore errors here } }
private void UpFunc() { if (MainListBox.SelectedItems.Count == 0) { return; } List <CTrigger> cTriggers = new List <CTrigger>(); foreach (CTrigger item in MainListBox.SelectedItems) { cTriggers.Add(item); } cTriggers.Sort((x, y) => { int xpos = triggerlist.IndexOf(x); int ypos = triggerlist.IndexOf(y); return(xpos.CompareTo(ypos)); }); if (MainListBox.Items.IndexOf(cTriggers.First()) == 0) { return; } foreach (CTrigger item in cTriggers) { UpItem(item); } foreach (CTrigger item in cTriggers) { MainListBox.SelectedItems.Add(item); } MainListBox.ScrollIntoView(cTriggers.First()); mapEditor.SetDirty(); }
public HostUserControl() { // UserControls InitializeComponent(); this.DockPanel1.DataContext = this; UserControls = Assembly .GetEntryAssembly() .GetTypes() .Where(a => typeof(UserControl).IsAssignableFrom(a)) .GroupBy(a => a.Name?.Replace("UserControl", string.Empty)) .OrderBy(a => a.Key) .ToDictionaryOnIndex() .ToDictionary(a => a.Key, a => new Func <UserControl>(() => (UserControl)Activator.CreateInstance(a.Value))); MainListBox.ItemsSource = UserControls; ContentControl1.Content = UserControls.FirstOrDefault().Value.Invoke(); MainListBox.SelectAddChanges().Subscribe(async => { ContentControl1.Content = ((KeyValuePair <string, Func <UserControl> >)MainListBox.SelectedItem).Value.Invoke(); }); }
private void ApplicationBarIconButton_Click_ScrollDown(object sender, EventArgs e) { MainListBox.ScrollToBottom(); }