private void DownClick(object sender, RoutedEventArgs e) { FrameworkElement ele = sender as FrameworkElement; if (ele == null) { return; } var alp = (AlphabetItem)ele.DataContext; var index = Alphabets.IndexOf(alp); AlphabetItem tmp = null; if (ActiveAlphabet == alp) { tmp = alp; } index--; if (index > -1) { Alphabets.Remove(alp); Alphabets.Insert(index, alp); if (tmp != null) { ActiveAlphabet = alp; } } AlphabetCollectionView.Refresh(); }
private void AddItemClick(object sender, RoutedEventArgs e) { var item = new AlphabetItem(); addItem(item); SelectedAlphabet = item; }
private static void OnActiveAlphabetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AlphabetPresentation b = (AlphabetPresentation)d; AlphabetItem newItem = (AlphabetItem)e.NewValue; AlphabetItem oldItem = (AlphabetItem)e.OldValue; if (newItem != null) { newItem.IsSelected = true; } if (oldItem != null) { oldItem.IsSelected = false; } }
public void SetAlphabetItems(List <AlphabetItemData> data) { if (Alphabets != null) { var x = Alphabets.Count - 1; for (int i = x; i >= 0; --i) { var item = Alphabets[i]; item.PropertyChanged -= new PropertyChangedEventHandler(item_PropertyChanged); } } Alphabets.Clear(); foreach (var item in data) { var tmp = new AlphabetItem(item); addItem(tmp); if (tmp.IsSelected == true) { ActiveAlphabet = tmp; } } }
public AlphabetItem(AlphabetItem item) { this.Data = item.Data; }
private void removeItem(AlphabetItem item) { item.PropertyChanged -= new PropertyChangedEventHandler(item_PropertyChanged); Alphabets.Remove(item); saveToSettings(); }
private void addItem(AlphabetItem item) { item.PropertyChanged += new PropertyChangedEventHandler(item_PropertyChanged); Alphabets.Add(item); saveToSettings(); }