// Methods public void AddUnit(UnitName uName) { // Add the unit to the collection ArmyNode tempANode = new ArmyNode(uName.TheUnit); startingArmies.Add(tempANode); // Listen to changes in the Display Name uName.PropertyChanged += tempANode.OnNameChange; // Listen to changes in the ArmyNode tempANode.PropertyChanged += OnArmyNodeChanged; }
protected void OnArmiesChange(object sender, EventArgs args) { // First case, this is a propogated event from StartingArmies if (sender is ArmyNode) { ArmyNode tempAN = sender as ArmyNode; string propChanged = (args as PropertyChangedEventArgs).PropertyName; // And now for the switch that'll handle eveything switch (propChanged) { case "NEAStartingCount": tempAN.TheUnit.StartsInNEA = tempAN.NEAStartingCount; break; case "ConStartingCount": tempAN.TheUnit.StartsInCon = tempAN.ConStartingCount; break; case "GPFStartingCount": tempAN.TheUnit.StartsInGPF = tempAN.GPFStartingCount; break; case "RoTStartingCount": tempAN.TheUnit.StartsInRoT = tempAN.RoTStartingCount; break; case "CalStartingCount": tempAN.TheUnit.StartsInCal = tempAN.CalStartingCount; break; case "PacStartingCount": tempAN.TheUnit.StartsInPac = tempAN.PacStartingCount; break; case "EUStartingCount": tempAN.TheUnit.StartsInEU = tempAN.EUStartingCount; break; case "RusStartingCount": tempAN.TheUnit.StartsInRus = tempAN.RusStartingCount; break; } } }
/// <summary> /// Our listener for changes to an ArmyNode inside StartingArmies /// </summary> /// <param name="sender">The ArmyNode that fired a PropertyChanged event</param> /// <param name="args">The property that was changed</param> protected void OnArmyNodeChanged(object sender, PropertyChangedEventArgs args) { // First, set up some ease of use handlers ArmyNode tempAN = sender as ArmyNode; if (tempAN == null) { // We don't care return; } // We actually don't care about this event, but want subsribers of our PropertyChanged // to be able to listen for changes in StartingArmies if (PropertyChanged != null) { // Bubble up PropertyChanged(tempAN, args); } }