private void SwitchRoomClick(object sender, RoutedEventArgs e) { //SimulationStepSwitch(); int roomcount = s.model.modelRooms.Count; if (roomcount >= 2) { Random r = new Random(10); MyRoom r1 = s.model.modelRooms.ElementAt(0); //r.Next(s.model.modelRooms.Count)); MyRoom r2 = s.model.modelRooms.ElementAt(1); //r.Next(s.model.modelRooms.Count)); s.SwitchRoom(ref r1, ref r2); } Paint(); }