/// <summary> /// Initializes a new instance of the <see cref="NewGameWindow"/> class. /// </summary> public NewGameWindow() { try { InitializeComponent(); errorLogViewModel = new ErrorLogViewModel(); newGameViewModel = new NewGameViewModel(); optionsViewModel = new OptionsViewModel(); this.Height = optionsViewModel.VerticalScaleNumber; this.Width = optionsViewModel.HorizontalScaleNumber; firstMap_Diff.IsEnabled = newGameViewModel.FindMap(newGameViewModel.FirstMapPath); secondMap_Diff.IsEnabled = newGameViewModel.FindMap(newGameViewModel.SecondMapPath); thirdMap_Diff.IsEnabled = newGameViewModel.FindMap(newGameViewModel.ThirdMapPath); fourthmapMap_Diff.IsEnabled = newGameViewModel.FindMap(newGameViewModel.ForthMapPath); fifthmap_Diff.IsEnabled = newGameViewModel.FindMap(newGameViewModel.FifthMapPath); } catch { } }
/// <summary> /// Handles the Loaded event of the Window control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void Window_Loaded(object sender, RoutedEventArgs e) { newGameViewModel = new NewGameViewModel(canvas.ActualWidth, canvas.ActualHeight); optionsViewModel = new OptionsViewModel(); this.DataContext = newGameViewModel; newGameViewModel.PresetValues(); foreach (var item in newGameViewModel.BallList) { Ball ujlabda = item; Ellipse ujLabdaEllipse = new Ellipse(); ImageBrush myBrush = new ImageBrush(); myBrush.ImageSource = new BitmapImage(new Uri(item.ImagePath,UriKind.Relative)); ujLabdaEllipse.Fill = myBrush; canvas.Children.Add(ujLabdaEllipse); Binding widthBinding = new Binding("Area.Width"); widthBinding.Source = ujlabda; ujLabdaEllipse.SetBinding(Ellipse.WidthProperty, widthBinding); Binding heightBinding = new Binding("Area.Height"); heightBinding.Source = ujlabda; ujLabdaEllipse.SetBinding(Ellipse.HeightProperty, heightBinding); Binding xBinding = new Binding("Area.X"); xBinding.Source = ujlabda; ujLabdaEllipse.SetBinding(Canvas.LeftProperty, xBinding); Binding yBinding = new Binding("Area.Y"); yBinding.Source = ujlabda; ujLabdaEllipse.SetBinding(Canvas.TopProperty, yBinding); } foreach (var item in newGameViewModel.BrickList) { Brick ujbrick = item; Rectangle ujBrickRect = new Rectangle(); ImageBrush myBrush = new ImageBrush(); myBrush.ImageSource = new BitmapImage(new Uri(item.ImagePath, UriKind.Relative)); ujBrickRect.Fill = myBrush; Binding widthBinding = new Binding("Area.Height"); widthBinding.Source = ujbrick; ujBrickRect.SetBinding(Rectangle.WidthProperty, widthBinding); Binding heightBinding = new Binding("Area.Width"); heightBinding.Source = ujbrick; ujBrickRect.SetBinding(Rectangle.HeightProperty, heightBinding); Binding xBinding = new Binding("Area.X"); xBinding.Source = ujbrick; ujBrickRect.SetBinding(Canvas.LeftProperty, xBinding); Binding yBinding = new Binding("Area.Y"); yBinding.Source = ujbrick; ujBrickRect.SetBinding(Canvas.TopProperty, yBinding); canvas.Children.Add(ujBrickRect); } foreach (var item in newGameViewModel.RacketList) { Racket racket = item; Rectangle ujracket = new Rectangle(); ImageBrush myBrush = new ImageBrush(); myBrush.ImageSource = new BitmapImage(new Uri(item.ImagePath, UriKind.Relative)); ujracket.Fill = myBrush; Binding widthBinding = new Binding("Area.Width"); widthBinding.Source = racket; ujracket.SetBinding(Rectangle.WidthProperty, widthBinding); Binding heightBinding = new Binding("Area.Height"); heightBinding.Source = racket; ujracket.SetBinding(Rectangle.HeightProperty, heightBinding); Binding xBinding = new Binding("Area.X"); xBinding.Source = racket; ujracket.SetBinding(Canvas.LeftProperty, xBinding); Binding yBinding = new Binding("Area.Y"); yBinding.Source = racket; ujracket.SetBinding(Canvas.TopProperty, yBinding); canvas.Children.Add(ujracket); } }