private void PlayFieldView_OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { // Crappy workaround MVVM -> code behind PlayFieldViewModel vm = DataContext as PlayFieldViewModel; if (vm != null) { vm.ClientChanged += OnClientChanged; if (vm.Client != null) { OnClientChanged(null, vm.Client); } } }
public MainWindowViewModel() { // IFactory factory = new Factory(); // IActionQueue actionQueue = new BlockingActionQueue(); // IAchievementManager manager = null; if (!IsInDesignMode) { // manager = factory.CreateAchievementManager(); manager.FindAllAchievements(); Settings.Default.Achievements = Settings.Default.Achievements ?? new AchievementsSettings(); Settings.Default.Achievements.Load(manager.Achievements); } // Create sub view models WinListViewModel = new WinListViewModel(); StatisticsViewModel = new StatisticsViewModel(); OptionsViewModel = new OptionsViewModel(); PartyLineViewModel = new PartyLineViewModel(); ConnectionViewModel = new ConnectionViewModel(); PlayFieldPlayerViewModel = new PlayFieldViewModel(); PlayFieldSpectatorViewModel = new PlayFieldSpectatorViewModel(); AchievementsViewModel = new AchievementsViewModel(); PlayFieldViewModel = PlayFieldPlayerViewModel; // by default, player view // ConnectionViewModel.LoginViewModel.OnConnect += OnConnect; // ClientChanged += OnClientChanged; if (!IsInDesignMode) { // Create client Client = new Client.Client(factory, actionQueue, manager); } }