public MainWindow() { Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("sv-SV"); InitializeComponent(); _gameViewModel = new SeaBattleTrophyGameViewModel(); SetupSeaMap(); SetupShipOrderControl(); SetupTurnControl(); SetupShipStatusControl(); SetupWindDisplay(); }
private void Reset() { if (_game != null) { _game.SeaMapSizeInPixels.PropertyChanged -= HandleSeaMapSizeInPixelsPropertyChanged; } ShipGrid.Children.Clear(); LandMassGrid.Children.Clear(); _game = null; }
private void HandleDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { var game = DataContext as SeaBattleTrophyGameViewModel; if (game == null) { throw new InvalidCastException("The data context should be of correct type"); } Reset(); _game = game; _game.SeaMapSizeInPixels.PropertyChanged += HandleSeaMapSizeInPixelsPropertyChanged; HandleSeaMapSizeInPixelsPropertyChanged(this, new PropertyChangedEventArgs(null)); AddShips(); AddLandMasses(); }