private void DiceList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { foreach (var thisItem in e.NewItems) { var newDice = (D)thisItem !; StandardDiceXF thisD = new StandardDiceXF(); DiceBindings(thisD, newDice); // well see what we need _thisStack !.Children.Add(thisD); } } if (e.Action == NotifyCollectionChangedAction.Replace) { if (e.OldItems.Count == e.NewItems.Count) { int x; var loopTo = e.OldItems.Count; for (x = 1; x <= loopTo; x++) { var oldDice = (D)e.OldItems[x - 1] !; var newDice = (D)e.NewItems[x - 1] !; var thisCon = FindControl(oldDice); thisCon !.BindingContext = newDice; } } else { throw new Exception("Not sure when the numbers don't match"); } } if (e.Action == NotifyCollectionChangedAction.Remove) { foreach (var thisItem in e.OldItems) { var oldDice = (D)thisItem !; var thisCon = FindControl(oldDice); _thisStack !.Children.Remove(thisCon); // because not there anymore. } } if (e.Action == NotifyCollectionChangedAction.Reset) { _thisStack !.Children.Clear(); // needs to clear and do nothing else because no dice left PopulateList(); } if (e.Action == NotifyCollectionChangedAction.Move) { if (e.OldStartingIndex == e.NewStartingIndex) { RefreshItems(); } else { var firstCon = _thisStack !.Children[e.OldStartingIndex]; _thisStack.Children.Remove(firstCon); _thisStack.Children.Insert(e.NewStartingIndex, firstCon); } } }
private void DiceBindings(StandardDiceXF thisGraphics, D thisDice) // needs the dice for the data context { thisGraphics.BindingContext = thisDice; thisGraphics.CommandParameter = thisDice; var thisBind = GetCommandBinding(nameof(DiceCup <D> .DiceCommand)); thisGraphics.SetBinding(StandardDiceXF.CommandProperty, thisBind); //hopefully i don't need extra on this one for sizes (?) }
private void PopulateList() { foreach (var firstDice in _diceList !) { StandardDiceXF thisGraphics = new StandardDiceXF(); // this does the bindings already as well thisGraphics.SendDiceInfo(firstDice); //this has to be done too. DiceBindings(thisGraphics, firstDice); _thisStack !.Children.Add(thisGraphics); } }