- Movement notifications trigger cage redraws through delegates.

CageWindow, Cage, Guest, and Animal classes and ICageable interface as specified in the diagram below.
OnImageUpdate delegate in the animal's Move method, after calling the Move method on the move behavior.Cage class.HandleImageUpdate method, call the cage's OnImageUpdate delegate.Add method after adding the caged item, plug the HandleImageUpdate method into the caged item's OnImageUpdate delegate.Then call the cage's OnImageUpdate method. This will bubble the caged item's notification up to the cage window.
Remove method after removing the caged item, unplug the HandleImageUpdate method from the caged item's OnImageUpdate delegate.Then call the cage's OnImageUpdate method. This will bubble the caged item's notification up to the cage window.
Update method into the cage's OnImageUpdate delegate.DrawItem method, just before adding the viewbox to the cage grid's children, set the viewbox's Tag property to the item.This will store the object in the viewbox for future reference.
Update method.try
{
this.Dispatcher.Invoke(new Action(delegate()
{
// code here
}));
}
catch (TaskCanceledException)
{
}Dispatcher.Invoke method, loop through the viewboxes in the cage grid's children.If the current viewbox's tag matches the item parameter, remove that viewbox from the cage grid and break. After looping, draw the item.
redrawTimer and the code that instantiates and starts it.window_Closed event handler.In it, just set the cage's OnImageUpdate delegate to null. This will help with serialization by removing any references the delegate might have to the window's Update method.
CageWindow.xaml.cs, add a parameter called zIndex of type int to the DrawItem method.Instead of adding the viewbox to the cage grid's children, insert it at the zIndex spot. Use the Insert method.
DrawAllItems method, define a zIndex variable before the loop and initialize it to 0.In the loop, pass the variable in to the DrawItem method, and then increment the variable.
Update method, define and instantiate a zIndex variable before the loop.Increment it inside the loop but after the if block. Then pass it in to the DrawItem method.
Show their cage. The overlapping animals should no longer flip back and forth between the foreground and the background.
Add properties to caged items indicating whether or not they are active.
IsActive property, get and set the moveTimer's Enabled property.IsActive setter, set the isActive field.The getter should return true if either isActive is true or the guest's adoptedAnimal is not null.
AddAnimal method, set the animal's IsActive property to true.RemoveAnimal method, set the animal's IsActive property to false.RemoveGuest method.CageWindow.xaml.cs's Update method, only call DrawItem if the item is active.Have the guest adopt an animal. The guest should appear in the cage window. Have the guest un-adopt their animal. The guest should disappear from the cage window.
The guest should appear in the cage window. Remove the adopted animal from the zoo. Both the animal and the guest should disappear from the cage window.
The guest should appear in the cage window. Remove the guest from the zoo. The guest should disappear from the cage window.
© 2026 Northcentral Technical College