void PacmanUC_Loaded(object sender, RoutedEventArgs e) { GamePresenter gp = ((GamePresenter)this.DataContext); //because FindName doesn't works inside viewbox, i should remap local fields Canvas cv = (Canvas)this.viewBox.Child; mouseTopPosition = FindName <LineSegment>(cv, "mouseTopPosition"); mouseBottomPosition = FindName <ArcSegment>(cv, "mouseBottomPosition"); this.ghost1 = FindName <GhostUC>(cv, "ghost1"); this.ghost2 = FindName <GhostUC>(cv, "ghost2"); this.ghost3 = FindName <GhostUC>(cv, "ghost3"); this.ghost4 = FindName <GhostUC>(cv, "ghost4"); gp.PacmanPresenter.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(PacmanPresenter_PropertyChanged); if (this.ghost1 != null) { ((GhostUCPresenter)this.ghost1.DataContext).GhostPresenter = gp.Ghost1; } if (this.ghost2 != null) { ((GhostUCPresenter)this.ghost2.DataContext).GhostPresenter = gp.Ghost2; } if (this.ghost3 != null) { ((GhostUCPresenter)this.ghost3.DataContext).GhostPresenter = gp.Ghost3; } if (this.ghost4 != null) { ((GhostUCPresenter)this.ghost4.DataContext).GhostPresenter = gp.Ghost4; } gp.CurrentGame.Audio = this; _gamepresenter = gp; mediaelem.MediaOpened += new RoutedEventHandler(mediaelem_MediaOpened); mediaelem.MediaEnded += new RoutedEventHandler(mediaelem_MediaEnded); mediaelem.MediaFailed += new EventHandler <ExceptionRoutedEventArgs>(mediaelem_MediaFailed); }
void FlyingScoreUC_Loaded(object sender, RoutedEventArgs e) { if (_presenter == null) { _presenter = this.DataContext as GamePresenter; if (_presenter != null) { _presenter.CurrentGame.FlyingScores.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(FlyingScores_CollectionChanged); } } }