public Ellipse getEllipse() { Ellipse ellipse = new Ellipse(); ellipse.Fill = Brushes.Red; ellipse.Stroke = Brushes.Black; Binding ellipseXBinding = new Binding("X"); ellipseXBinding.Source = this; ellipse.SetBinding(Canvas.LeftProperty, ellipseXBinding); Binding ellipseYBinding = new Binding("Y"); ellipseYBinding.Source = this; ellipse.SetBinding(Canvas.TopProperty, ellipseYBinding); ellipse.Width = 50; ellipse.Height = 50; return ellipse; }
internal void BindEllipse(Ellipse ellipse, PlotPointViewRenderer point) { Binding topBinding = new Binding(); topBinding.Path = new PropertyPath("Y"); topBinding.Mode = BindingMode.OneWay; topBinding.Source = point; ellipse.SetBinding(Canvas.TopProperty, topBinding); Binding leftBinding = new Binding(); leftBinding.Path = new PropertyPath("X"); leftBinding.Mode = BindingMode.OneWay; leftBinding.Source = point; ellipse.SetBinding(Canvas.LeftProperty, leftBinding); Binding colorBinding = new Binding(); colorBinding.Path = new PropertyPath("InnerColor"); colorBinding.Mode = BindingMode.OneWay; colorBinding.Source = point; colorBinding.Converter = ColorBrushConverter.Instance; ellipse.SetBinding(Ellipse.FillProperty, colorBinding); Binding strokeBinding = new Binding(); strokeBinding.Path = new PropertyPath("OuterColor"); strokeBinding.Mode = BindingMode.OneWay; strokeBinding.Source = point; strokeBinding.Converter = ColorBrushConverter.Instance; ellipse.SetBinding(Ellipse.StrokeProperty, strokeBinding); Binding widthBinding = new Binding(); widthBinding.Path = new PropertyPath("Width"); widthBinding.Mode = BindingMode.OneWay; widthBinding.Source = point; ellipse.SetBinding(Ellipse.WidthProperty, widthBinding); Binding heightBinding = new Binding(); heightBinding.Path = new PropertyPath("Height"); heightBinding.Mode = BindingMode.OneWay; heightBinding.Source = point; ellipse.SetBinding(Ellipse.HeightProperty, heightBinding); }
public Ellipse build( Random random ) { Ellipse ellipse = new Ellipse(); ellipse.Width = DIAMETER; ellipse.Height = DIAMETER; ellipse.Fill = new SolidColorBrush(createRandomColor(random)); ellipse.Stroke = Brushes.Black; ellipse.StrokeThickness = 1; Binding ellipseXBinding = new Binding("X"); ellipseXBinding.Source = this; ellipse.SetBinding(Canvas.LeftProperty, ellipseXBinding); Binding ellipseYBinding = new Binding("Y"); ellipseYBinding.Source = this; ellipse.SetBinding(Canvas.TopProperty, ellipseYBinding); return ellipse; }
/// <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); } }
public void DataContext_Applied3 () { // Create an ellipse which will bind to the parent datacontext Ellipse e = new Ellipse (); e.SetBinding (Ellipse.HeightProperty, new Binding ()); // Check to see if the binding is applied correctly after the FE is loaded Canvas c = new Canvas { DataContext = 100.0 }; c.Children.Add (e); Assert.IsTrue (double.IsNaN (e.Height), "#1"); CreateAsyncTest (c, () => Assert.AreEqual (100, e.Height, "#2") ); }
private void InitLights(int amount) { movingHeads = new Ellipse[amount]; for (int i = 0; i < amount; i++) { // Ellipse representing a moving-head Binding bDataContext = new Binding("MovingHeads[" + i + "]"); Binding bTop = new Binding("Pos.Y"); Binding bLeft = new Binding("Pos.X"); bTop.Converter = new HeightConverter(); bLeft.Converter = new WidthConverter(); Ellipse e = new Ellipse(); e.Name = "mh" + i; e.Height = Const.MH_RADIUS * 2; e.Width = Const.MH_RADIUS * 2; e.Fill = new SolidColorBrush(Color.FromRgb(255, 153, 51)); e.SetBinding(Ellipse.DataContextProperty, bDataContext); e.SetBinding(Canvas.TopProperty, bTop); e.SetBinding(Canvas.LeftProperty, bLeft); rootCanvas.Children.Add(e); // Data of moving-head Binding bMH = new Binding("MovingHeads[" + i + "]"); MovingHeadData mhDataView = new MovingHeadData(); mhDataView.SetBinding(MovingHeadData.MovingHeadProperty, bMH); rootOfMHData.Children.Add(mhDataView); } }
/// <summary> /// Shape of the ball. /// </summary> /// <returns>ballEllipse</returns> public Ellipse GetEllipse() { ImageBrush imgBrush = new ImageBrush(); imgBrush.ImageSource = new BitmapImage(new Uri(ballImage, UriKind.Relative)); Ellipse ballEllipse = new Ellipse(); ballEllipse.Fill = imgBrush; ballEllipse.Width = radius * 2; ballEllipse.Height = radius * 2; Binding ellipseXBinding = new Binding("PositionX"); ellipseXBinding.Source = this; ballEllipse.SetBinding(Canvas.LeftProperty, ellipseXBinding); Binding ellipseYBinding = new Binding("PositionY"); ellipseYBinding.Source = this; ballEllipse.SetBinding(Canvas.TopProperty, ellipseYBinding); return ballEllipse; }
public Ellipse buildPlanet() { Ellipse ellipse = new Ellipse(); ellipse.Width = this.Radius * 2; ellipse.Height = this.Radius * 2; ellipse.Fill = this.brush; Binding xBinding = new Binding("PlanetRectLeft"); xBinding.Source = this; ellipse.SetBinding(Canvas.LeftProperty, xBinding); Binding yBinding = new Binding("PlanetRectTop"); yBinding.Source = this; ellipse.SetBinding(Canvas.TopProperty, yBinding); ellipse.MouseDown += ellipse_MouseDown; return ellipse; }
/// <summary> /// Shape of the ball. /// </summary> /// <returns>The ball's ellipse.</returns> public Ellipse GetEllipse() { // Set the ball's image as the set image. ImageBrush imgBrush = new ImageBrush(); imgBrush.ImageSource = new BitmapImage(new Uri(ImagePath, UriKind.Relative)); // Create the ellipse. Ellipse ballEllipse = new Ellipse(); ballEllipse.Fill = imgBrush; ballEllipse.Width = Area.Width; ballEllipse.Height = Area.Height; // Bind the X position of the ball ellipse to the canvas. Binding ellipseXBinding = new Binding("Area.X"); ellipseXBinding.Source = this; ballEllipse.SetBinding(Canvas.LeftProperty, ellipseXBinding); // Bind the Y position of the ball ellipse to the canvas. Binding ellipseYBinding = new Binding("Area.Y"); ellipseYBinding.Source = this; ballEllipse.SetBinding(Canvas.TopProperty, ellipseYBinding); // Bind the width of the ball ellipse to the canvas. Binding ellipseWidthBinding = new Binding("Area.Width"); ellipseWidthBinding.Source = this; ballEllipse.SetBinding(Canvas.WidthProperty, ellipseWidthBinding); // Bind the height of the ball ellipse to the canvas. Binding ellipseHeightBinding = new Binding("Area.Height"); ellipseHeightBinding.Source = this; ballEllipse.SetBinding(Canvas.HeightProperty, ellipseHeightBinding); return ballEllipse; }
public void Reset() { ConvertToColor ctc = new ConvertToColor(); Board = new Tile[7, 7]; BoardState = BoardStateEnum.Normal; RowPicked = ColPicked = -1; LayoutRoot.Children.Clear(); for (int r = 0; r < 7; r++) { for (int c = 0; c < 7; c++) { Board[r, c] = new Tile(r, c); Shape rect = new Ellipse(); rect.Margin = new Thickness(5); Grid.SetRow(rect, r); Grid.SetColumn(rect, c); Binding bb = new Binding(); bb.Source = Board[r, c]; bb.Converter = ctc; bb.Path = new PropertyPath("State"); rect.SetBinding(Ellipse.FillProperty, bb); LayoutRoot.Children.Add(rect); if (Board[r, c].State != TileStateEnum.Blocked) { rect.Stroke = Brushes.Black; rect.StrokeThickness = 1; } rect.MouseDown += new MouseButtonEventHandler(rect_MouseDown); } } }
public Ellipse getEllipse() { Ellipse ellipse = new Ellipse(); ellipse.Fill = new SolidColorBrush(this.color); ellipse.Stroke = Brushes.Black; Binding ellipseXBinding = new Binding("X"); ellipseXBinding.Source = this; ellipse.SetBinding(Canvas.LeftProperty, ellipseXBinding); Binding ellipseYBinding = new Binding("Y"); ellipseYBinding.Source = this; ellipse.SetBinding(Canvas.TopProperty, ellipseYBinding); ellipse.Width = this.Diameter; ellipse.Height = this.Diameter; return ellipse; }