private void ShipControl_OnLoaded(object sender, RoutedEventArgs e) { Ship.SubsystemUpdated += status => Dispatcher.BeginInvoke(new Action(() => Ship_SubsystemUpdated(status))); Ship.OnlineChanged += () => Dispatcher.BeginInvoke(new Action(Ship_OnlineChanged)); MainGroupBox.Header = Ship.Name; foreach (var shipSubsystemStatuse in Ship.GetAllSubsystemsStatus()) { var board = new BoardGUI { Status = shipSubsystemStatuse, SubsystemName = Ship.GetSubsystemName(shipSubsystemStatuse.SubSystemNum) }; board.StatusChanged += board_StatusChanged; _boards.Add(board); BoardStackPanel.Children.Add(board); board.Update(); } foreach (var shipRoomsID in Ship.ShipRoomsIDs) { var button = new Button { Content = Ship.GetRoomName(shipRoomsID), }; byte id = shipRoomsID; //Access to local closure. C# 5.0 will fix it button.Click += (o, args) => ClickRoomHit(id); HitStackPanel.Children.Add(button); } Ship_OnlineChanged(); }