public void MonitorControl(Panel panel)
        {
            Monitor = new Rectangle {Fill = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0))};
			Monitor.SetValue(Grid.RowSpanProperty, int.MaxValue - 1);
			Monitor.SetValue(Grid.ColumnSpanProperty, int.MaxValue - 1);

	        Monitor.ManipulationMode = ManipulationModes.All;
			Monitor.ManipulationStarted += MonitorManipulationStarted;
			Monitor.ManipulationDelta += MonitorManipulationDelta;

            panel.Children.Add(Monitor);
        }
Exemple #2
0
        public override Rectangle Render()
        {
            Rectangle rectangle = new Rectangle();

            rectangle.Fill = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));

            rectangle.Height = Utility.BULLET_SIZE * 2;
            rectangle.Width = Utility.BULLET_SIZE;

            rectangle.SetValue(Canvas.LeftProperty, _position.X);
            rectangle.SetValue(Canvas.TopProperty, _position.Y);
            _participant = rectangle;

            return rectangle;
        }
        private void Activate(Point2D item)
        {
            if (Map == null || Map.Layers == null)
            {
                return;
            }
            DrawLayer = new ElementsLayer();
            Map.Layers.Add(DrawLayer);
            rectangle = new Rectangle();
            rectangle.Stroke = this.Stroke;
            rectangle.StrokeThickness = this.StrokeThickness;
            rectangle.StrokeMiterLimit = this.StrokeMiterLimit;
            rectangle.StrokeDashOffset = this.StrokeDashOffset;
            rectangle.StrokeDashArray = this.StrokeDashArray;
            rectangle.StrokeDashCap = this.StrokeDashCap;
            rectangle.StrokeEndLineCap = this.StrokeEndLineCap;
            rectangle.StrokeLineJoin = this.StrokeLineJoin;
            rectangle.StrokeStartLineCap = this.StrokeStartLineCap;
            rectangle.Opacity = this.Opacity;
            rectangle.Fill = this.Fill;

            rectangle.SetValue(ElementsLayer.BBoxProperty , new Rectangle2D(item , item));
            DrawLayer.Children.Add(rectangle);

            isActivated = true;
            isDrawing = true;
        }
 // Create an 8x8 Matrix UI that can turn LEDs on and off
 private void CreateXAMLMatrix()
 {
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             Rectangle r = new Rectangle();
             r.Name = string.Format("rect{0}{1}", i, j);
             r.SetValue(Grid.RowProperty, i);
             r.SetValue(Grid.ColumnProperty, j);
             r.Fill = new SolidColorBrush(Windows.UI.Colors.Black);
             r.PointerPressed += new PointerEventHandler(grdMatrix_pointer_pressed);
             grdMatrix.Children.Add(r);
         }
     }
 }
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            rectangle = new Rectangle();
            rectangle.Fill = new SolidColorBrush(Colors.HotPink);
            rectangle.Width = 100;
            rectangle.Height = 100;

            rectangle.PointerPressed += new PointerEventHandler(OnRectanglePointerPressed);
            rectangle.PointerMoved += new PointerEventHandler(OnRectanglePointerMove);
            rectangle.PointerReleased += new PointerEventHandler(OnRectanglePointerReleased);

            rectangle.SetValue(Canvas.LeftProperty, 0);
            rectangle.SetValue(Canvas.TopProperty, 0);

            myCanvas.Children.Add(rectangle);
        }
 private void CreateSquaresOfType(int rows, int cols, Grid grid, double width, double margin, string name)
 {
     for (int row = 0; row < rows; row++)
     {
         grid.RowDefinitions.Add(new RowDefinition());
         for (int col = 0; col < cols; col++)
         {
             grid.ColumnDefinitions.Add(new ColumnDefinition());
             var rect = new Rectangle() { Width = width, Height = width, Margin = new Thickness(0, 0, margin, margin), Fill = new SolidColorBrush(Colors.White)/*, Opacity = 0.2*/ };
             grid.Children.Add(rect);
             rect.SetValue(Grid.RowProperty, row);
             rect.SetValue(Grid.ColumnProperty, col);
             var binding = new Binding();
             binding.Path = new PropertyPath(string.Format("Squares{1}[{0}]", row * cols + col, name));
             rect.SetBinding(OpacityProperty, binding);
         }
     }
 }
        public Tower(Canvas canvas, int x, int y, int v, int delay, int radius, BitmapImage img)
        {
            ImageBrush imgBrush = new ImageBrush();
            imgBrush.ImageSource = img;
            this.rect = new Rectangle();
            rect.Fill = imgBrush;
            rect.SetValue(Canvas.LeftProperty, x);
            rect.SetValue(Canvas.TopProperty, y);
            rect.Width = 45;
            rect.Height = 65;
            canvas.Children.Add(rect);

            this.x = x;
            this.y = y;
            //this.img = img;
            this.radius = radius;
            this.bulletVelocity = v;
            this.delay = delay;
            this.shotDelayCount = delay;
        }
        public void setImage(Canvas canvas, BitmapImage img)
        {
            /*
            Random r = new Random();
            byte red = (byte)r.Next(0, byte.MaxValue + 1);
            byte green = (byte)r.Next(0, byte.MaxValue + 1);
            byte blue = (byte)r.Next(0, byte.MaxValue + 1);
            Brush brush = new SolidColorBrush(Windows.UI.Color.FromArgb(255, red, green, blue));
            */

            ImageBrush imgBrush = new ImageBrush();
            imgBrush.ImageSource = img;

            this.rect = new Rectangle();
            rect.Fill = imgBrush;
            //rect.Fill = brush;
            rect.SetValue(Canvas.LeftProperty, x);
            rect.SetValue(Canvas.TopProperty, y);
            rect.Width = 20;
            rect.Height = 20;
            canvas.Children.Add(rect);
        }
        public Unit(Canvas canvas, int x, int y, BitmapImage img, List<Point> path, double health)
        {
            this.health = health;

            ImageBrush imgBrush = new ImageBrush();
            imgBrush.ImageSource = img;
            this.rect = new Rectangle();
            rect.Fill = imgBrush;
            rect.SetValue(Canvas.LeftProperty, x);
            rect.SetValue(Canvas.TopProperty, y);
            rect.Width = 72;
            rect.Height = 72;
            canvas.Children.Add(rect);

            this.x = x;
            this.y = y;
            this.vx = 0;
            this.vy = 0;
            this.velocity = 2;
            this.path = path;
            this.isFinish = false;
            this.stepIndex = 0;
        }
        private DependencyObject CriaMeuPin()
        {
            var MeuGrid = new Grid();
            MeuGrid.RowDefinitions.Add(new RowDefinition());
            MeuGrid.RowDefinitions.Add(new RowDefinition());
            MeuGrid.Background = new SolidColorBrush(Colors.Transparent);

            var MeuRetangulo = new Rectangle { Fill = new SolidColorBrush(Colors.Red), Height = 10, Width = 22 };
            MeuRetangulo.SetValue(Grid.RowProperty, 0);
            MeuRetangulo.SetValue(Grid.ColumnProperty, 0);
            MeuGrid.Children.Add(MeuRetangulo);

            var MeuPoligono = new Polygon()
            {
                Points = new PointCollection() { new Point(1, 0), new Point(22, 0), new Point(11, 40) },
                Stroke = new SolidColorBrush(Colors.Red),
                Fill = new SolidColorBrush(Colors.Red)
            };
            MeuPoligono.SetValue(Grid.RowProperty, 1);
            MeuPoligono.SetValue(Grid.ColumnProperty, 0);
            MeuGrid.Children.Add(MeuPoligono);

            return MeuGrid;
        }
		private void RefreshCanvas()
		{
			_mainCanvas.Children.Clear();
			var mainImage = new Image() { Source = _viewModel.Image };
			mainImage.PointerPressed += MainImage_PointerPressed;
			_mainCanvas.Children.Add(mainImage);
			foreach (var frame in _viewModel.Frames)
			{
				var frameRectangle = new Rectangle()
				{
					Width = frame.Width,
					Height = frame.Height,
					Stroke = new SolidColorBrush()
					{
						Color = Colors.White,
					},
				};
				frameRectangle.SetValue(Canvas.LeftProperty, frame.X);
				frameRectangle.SetValue(Canvas.TopProperty, frame.Y);
				_mainCanvas.Children.Add(frameRectangle);
				if (frame.Image != null)
				{
					var frameImage = new Image()
					{
						Width = frame.Width,
						Height = frame.Height,
						Source = frame.Image,
					};
					frameImage.SetValue(Canvas.LeftProperty, frame.X);
					frameImage.SetValue(Canvas.TopProperty, frame.Y);
					_mainCanvas.Children.Add(frameImage);
				}
			}
		}
        public void FillWaveForm(WaveForm wave)
        {
            Children.Clear();
            RowDefinitions.Clear();
            ColumnDefinitions.Clear();

            if (wave != null)
            {
                //create the waveform
                int index = 0;
                int sample;
                RowDefinition row1 = new RowDefinition();
                row1.Height = new GridLength(2, GridUnitType.Star);
                RowDefinitions.Add(row1);
                RowDefinition row2 = new RowDefinition();
                row1.Height = new GridLength(1, GridUnitType.Star);
                RowDefinitions.Add(row2);
                for (sample = 0; sample < wave.Samples.Length; sample = sample + 6)
                {
                    int s = sample / 6;
                    if((s & 1) == 0)
                    {
                        int i = wave.Samples[sample];
                        ColumnDefinition col = new ColumnDefinition();
                        col.Width = new GridLength(1, GridUnitType.Star);
                        ColumnDefinitions.Add(col);
                        Thickness margin = new Thickness();
                        margin.Bottom = 1;
                        margin.Top = 1;
                        Rectangle r = new Rectangle
                        {
                            Height = i / 2,
                            Margin = margin,
                            VerticalAlignment = VerticalAlignment.Bottom
                        };
                        Rectangle r2 = new Rectangle
                        {
                            Height = i / 4,
                            Margin = margin,
                            VerticalAlignment = VerticalAlignment.Top
                        };
                        r.SetValue(ColumnProperty, index);
                        r.SetValue(RowProperty, 0);
                        r2.SetValue(ColumnProperty, index);
                        r2.SetValue(RowProperty, 1);
                        r.Fill = new SolidColorBrush(Colors.White);
                        r2.Fill = new SolidColorBrush(Colors.White);
                        Children.Add(r);
                        Children.Add(r2);
                        index = index + 2;
                    }
                    else
                    {
                        ColumnDefinition col = new ColumnDefinition();
                        col.Width = new GridLength(1, GridUnitType.Star);
                        ColumnDefinitions.Add(col);
                    }
                    
                }
                _slider.Minimum = 0;
                _slider.StepFrequency = 1;
                _slider.IsThumbToolTipEnabled = false;
                _slider.Style = (Style) Application.Current.Resources["WaveFormSlider"];
                _slider.SetValue(ColumnSpanProperty, index);
                _slider.ValueChanged += Slider_ValueChanged;
                Children.Add(_slider);
                _playbackTimer.Start();
            }
        }
        private void updateMyScreen(AccelerometerReadingChangedEventArgs e)
        {
            // updates the textblocks

            previousReading = currentReading;
            currentReading = e.Reading;

            if (previousReading != null)
            {

                double xValue = currentReading.AccelerationX - previousReading.AccelerationX;
                double yValue = currentReading.AccelerationY - previousReading.AccelerationY;
                double zValue = currentReading.AccelerationZ - previousReading.AccelerationZ;

                if (xValue < 0) xValue -= 2 * xValue;
                if (yValue < 0) yValue -= 2 * yValue;
                if (zValue < 0) zValue -= 2 * zValue;

                data_width.Text = String.Format("{0,5:0.00}", xValue);
                data_length.Text = String.Format("{0,5:0.00}", yValue);
                data_depth.Text = String.Format("{0,5:0.00}", zValue);

                // draws on the canvas

                double currentXOnGraph = Math.Abs((xValue * 200) - 200);
                double currentYOnGraph = Math.Abs((yValue * 200) - 200);
                double currentZOnGraph = Math.Abs((zValue * 200) - 200);

                Rectangle xPoint = new Rectangle();
                Rectangle yPoint = new Rectangle();
                Rectangle zPoint = new Rectangle();

                xPoint.Fill = new SolidColorBrush(Colors.Red);
                yPoint.Fill = new SolidColorBrush(Colors.Blue);
                zPoint.Fill = new SolidColorBrush(Colors.Green);

                // set the pixel size 

                xPoint.Width = 1;
                xPoint.Height = 2;
                yPoint.Width = 1;
                yPoint.Height = 2;
                zPoint.Width = 1;
                zPoint.Height = 2;

                // These pixels will be "pasted into" the canvas by setting their position 
                // according to the currentX/Y/Z-on-graph values. To set their position 
                // relative to the canvas, pass the canvas properties on to the pixels via 
                // the SetValue method. Use a generic iterator to determine the distance 
                // the pixel should be from the left side of the canvas.

                xPoint.SetValue(Canvas.LeftProperty, iterateur);
                xPoint.SetValue(Canvas.TopProperty, currentXOnGraph);
                yPoint.SetValue(Canvas.LeftProperty, iterateur);
                yPoint.SetValue(Canvas.TopProperty, currentYOnGraph);
                zPoint.SetValue(Canvas.LeftProperty, iterateur);
                zPoint.SetValue(Canvas.TopProperty, currentZOnGraph);

                // finally, associate pixels with the canvas

                my_canvas.Children.Add(xPoint);
                my_canvas.Children.Add(yPoint);
                my_canvas.Children.Add(zPoint);

                if (iterateur == 399)
                {
                    my_canvas.Children.Clear();
                    iterateur = 0;
                }
                else
                {
                    iterateur++;
                }
            }

        }
Exemple #14
0
        void UpdateGrid()
        {
            if (_root == null || ItemsSource == null)
            {
                return;
            }
            _root.Children.Clear();
            _root.ColumnDefinitions.Clear();
            _independentValues.Clear();
            _dependentValues.Clear();
            BindingEvaluator independentBinding = new BindingEvaluator(IndependentValuePath);
            BindingEvaluator dependentBinding = new BindingEvaluator(DependentValuePath);

            int column = 0;
            foreach (var item in ItemsSource)
            {
                var independentValue = independentBinding.Eval(item).ToString();
                var dependentValue = (long)dependentBinding.Eval(item);
                _dependentValues.Add(dependentValue);
                _root.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });

                TextBlock independentTB = new TextBlock();
                independentTB.Text = independentValue;
                independentTB.FontSize = IndependentValueFontSize;
                independentTB.Foreground = IndependentValueBrush;
                independentTB.VerticalAlignment = VerticalAlignment.Center;
                independentTB.HorizontalAlignment = HorizontalAlignment.Center;
                independentTB.SetValue(Grid.RowProperty, 3);
                independentTB.SetValue(Grid.ColumnProperty, column++);
                _root.Children.Add(independentTB);
            }
            Rectangle rc = new Rectangle();
            rc.Fill = GridLineBrush;
            rc.Height = 1;
            rc.SetValue(Grid.RowProperty, 1);
            rc.SetValue(Grid.ColumnSpanProperty, column);
            _root.Children.Add(rc);

            var min = _dependentValues.Min();
            var max = _dependentValues.Max();
            long temp = 0;
            if (min >= 0 && max >= 0)
            {
                temp = max;
            }
            else if (min < 0 && max >= 0)
            {
                temp = max - min;
            }
            else if (max < 0)
            {
                temp = -min;
            }

            var height = (this.ActualHeight - 1 - 30) / temp;


            for (int i = 0; i < _dependentValues.Count; i++)
            {
                var dependentValue = _dependentValues[i];
                TextBlock dependentTB = new TextBlock();
                dependentTB.Text = dependentValue.ToString();
                dependentTB.FontSize = DependentValueFontSize;
                dependentTB.Foreground = dependentValue >= 0 ? PositiveValueBrush : NegativeValueBrush;
                dependentTB.VerticalAlignment = dependentValue > 0 ? VerticalAlignment.Top : VerticalAlignment.Bottom;
                dependentTB.HorizontalAlignment = HorizontalAlignment.Center;
                dependentTB.SetValue(Grid.RowProperty, dependentValue > 0 ? 2 : 0);
                dependentTB.SetValue(Grid.ColumnProperty, i);

                Rectangle dependentRC = new Rectangle();
                dependentRC.Fill = dependentValue >= 0 ? PositiveValueBrush : NegativeValueBrush;
                dependentRC.Height = Math.Abs(height * dependentValue);
                dependentRC.Margin = new Thickness(20, 0, 20, 0);
                dependentRC.VerticalAlignment = dependentValue <= 0 ? VerticalAlignment.Top : VerticalAlignment.Bottom;
                dependentRC.SetValue(Grid.RowProperty, dependentValue <= 0 ? 2 : 0);
                dependentRC.SetValue(Grid.ColumnProperty, i);
                _root.Children.Add(dependentRC);
                _root.Children.Add(dependentTB);

            }
        }
Exemple #15
0
        private void InitializeDayLabelBoxes()
        {
            int column = 0;
            CalendarGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            foreach (var day in Enum.GetValues(typeof(DayOfWeek)))
            {
                //Runtime generate controls and setting style
                Rectangle box = new Rectangle();
                box.Style = Application.Current.Resources["CalendarLabelBox"] as Style;
                box.SetValue(Grid.RowProperty, 0);
                box.SetValue(Grid.ColumnProperty, column);

                TextBlock textBlock = new TextBlock();
                textBlock.Style = Application.Current.Resources["CalendarLabel"] as Style;
                textBlock.Text = day.ToString();

                //Runtime setting the control Grid.Row and Grid.Column XAML property value
                textBlock.SetValue(Grid.RowProperty, 0);
                textBlock.SetValue(Grid.ColumnProperty, column);

                //Adding the box and the textblock control to the Grid during runtime
                CalendarGrid.Children.Add(box);
                CalendarGrid.Children.Add(textBlock);

                column++;
            }
        }
        //-------------------------------------------------------------------------------
        #region -Display 表示
        //-------------------------------------------------------------------------------
        //
        private async Task Display(List<DispCircleInfo> info)
        {
            var cc = await _catalogData.GetComiketInfo();

            _serialNoToRect.Clear();
            _rectToMapIndex.Clear();
            Action<Canvas> deleteRects = (Canvas canvas) =>
            {
                for (int i = canvas.Children.Count - 1; i >= 0; --i) {
                    var child = canvas.Children[i];
                    if (child is Rectangle) {
                        canvas.Children.RemoveAt(i);
                    }
                }
            };

            deleteRects(canvasMap1_E123);
            deleteRects(canvasMap1_E456);
            deleteRects(canvasMap1_W);
            deleteRects(canvasMap2_E123);
            deleteRects(canvasMap2_E456);
            deleteRects(canvasMap2_W);
            deleteRects(canvasMap3_E123);
            deleteRects(canvasMap3_E456);
            deleteRects(canvasMap3_W);

            foreach (var item in info) {
                int canvasIndex = await GetCanvasIndex(item);

                if (canvasIndex == -1) { Debug.Assert(false); continue; }
                Canvas canvas = CANVASES[canvasIndex];

                var rect = ComiketUtil.GetCircleRect(item.MapX, item.MapY, cc.mapSizeW, cc.mapSizeH, item.Layout, item.SpaceNoSub, await _catalogData.GetAreaChar(item.Block));
                Rectangle rectangle = new Rectangle()
                {
                    Width = rect.Width,
                    Height = rect.Height,
                    Fill = item.MarkColor,
                    Opacity = 0.8
                };
                rectangle.SetValue(Canvas.LeftProperty, rect.Left);
                rectangle.SetValue(Canvas.TopProperty, rect.Top);
                rectangle.SetValue(Canvas.ZIndexProperty, 4);

                rectangle.Tag = item;
                rectangle.Tapped += rectangle_Tapped;

                canvas.Children.Add(rectangle);

                _rectToMapIndex.Add(rectangle, canvasIndex);
                _serialNoToRect.Add(item.SerialNo, rectangle);
            }


            this.defaultViewModel["Items"] = info.GroupBy(dci => dci.Day)
                                                 .OrderBy(grp => grp.Key);
        }
Exemple #17
0
        //double timeToLive,
        public async static void Show(
            string message, 
            string title,
            Brush modalAdornerBrush, 
            Brush backgroundBrush, 
            Brush foregroundTextBrush, 
            double width = 300, 
            double height = 180, 
            string metroIcon = "", 
            string imageIcon = "", 
            double scaleIcon = 1, 
            double translateXIcon = 0, 
            double translateYIcon = 0,
            string yesLabel = "Yes",
            string yesMessengerContent = "",
            string yesMessengerIdentifier = "",
            string noLabel = "No",
            string noMessengerContent = "",
            string noMessengerIdentifier = "",
            GeneralSystemWideMessage msgToPassAlong = null
            )
        {

            if (MsgBoxService._rootControl != null)
            {
                DispatchedHandler invokedHandler = new DispatchedHandler(() =>
                {
                    if (MsgBoxService._rootControl == null) //|| MsgBoxService._rootControl.Visibility == Visibility.Visible)
                    {
                        return;
                    }


                    //modal adorner
                    Rectangle rectModalAdorner = new Rectangle();
                    rectModalAdorner.Fill = modalAdornerBrush;
                    rectModalAdorner.Opacity = 0.4;
                    rectModalAdorner.HorizontalAlignment = HorizontalAlignment.Stretch;
                    rectModalAdorner.VerticalAlignment = VerticalAlignment.Stretch;
                    rectModalAdorner.SetValue(Canvas.ZIndexProperty, -2);
                    MsgBoxService._rootControl.Children.Add(rectModalAdorner);


                    //message background
                    Rectangle rectBackground = new Rectangle();
                    rectBackground.Fill = backgroundBrush;
                    rectBackground.HorizontalAlignment = HorizontalAlignment.Stretch;
                    rectBackground.VerticalAlignment = VerticalAlignment.Center;
                    rectBackground.Height = height + 80;
                    rectBackground.SetValue(Canvas.ZIndexProperty, -1);
                    MsgBoxService._rootControl.Children.Add(rectBackground);


                    MsgBoxService._rootControl.Visibility = Visibility.Visible;

                    //message
                    MsgBoxView msgBoxView = new MsgBoxView(
                        message, 
                        "", 
                        foregroundTextBrush,
                        metroIcon : metroIcon,
                        imageIcon : imageIcon, 
                        scaleIcon : scaleIcon, 
                        translateXIcon : translateXIcon, 
                        translateYIcon : translateYIcon,
                        yesLabel : yesLabel,
                        yesMessengerContent : yesMessengerContent,
                        yesMessengerIdentifier : yesMessengerIdentifier,
                        noLabel : noLabel ,
                        noMessengerContent : noMessengerContent,
                        noMessengerIdentifier: noMessengerIdentifier,
                        msgToPassAlong: msgToPassAlong
                        );

                    msgBoxView.Width = width;
                    msgBoxView.Height = height;
                    msgBoxView.Margin = new Thickness(3);
                    msgBoxView.HorizontalAlignment =  HorizontalAlignment.Center;
                    msgBoxView.VerticalAlignment = VerticalAlignment.Center;
                    msgBoxView.BackgroundFill = backgroundBrush;
                    msgBoxView.MessageTextForegroundColor = foregroundTextBrush;
                    //msgBoxView.OnClosing += new EventHandler(MsgBoxService.view_OnClosing);
                    msgBoxView.Show();

                    MsgBoxService._rootControl.Children.Add(msgBoxView);


                    //MsgBoxService._MsgboxContainer.Children.Insert(0, msgBoxView);

 
                });
                await MsgBoxService._rootControl.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, invokedHandler);

                
            
            }

        }
Exemple #18
0
        private void initialiseGameGrid()
        {
            //          < Rectangle Grid.Row = "0"
            //           Grid.Column = "1"
            //           x:Name = "square01"
            //           Height = "98" Width = "98"
            //           HorizontalAlignment = "Center"
            //           VerticalAlignment = "Center"
            //           Fill = "Green" />

            // create a rectangle object
            Rectangle mySquare; // variable

            // need to add 9 squares in a loop
            int i, j;

            for (i = 0; i <= 2; i++)
            {
                for (j = 0; j <= 2; j++)
                {
                    mySquare = new Rectangle();
                    mySquare.Height = 98;
                    mySquare.Width = 98;
                    mySquare.HorizontalAlignment = HorizontalAlignment.Center;
                    mySquare.VerticalAlignment = VerticalAlignment.Center;
                    mySquare.Fill = new SolidColorBrush(Colors.Purple);
                    mySquare.Name = "R" + i.ToString() + "C" + j.ToString();

                    //set the grid.row and grid.column values
                    //can't set mySquare.Grid.Row
                    mySquare.SetValue(Grid.RowProperty, i);
                    mySquare.SetValue(Grid.ColumnProperty, j);

                    // add tap event handler
                    mySquare.Tapped += MySquare_Tapped;

                    grdGame.Children.Add(mySquare);
                } // for
            } // for
        }
 private void ShowVisual()
 {
     if (listViewItemHighlighted != null)
     {
         visualIndicator = listViewItemHighlighted.FindName("VISUAL_INDICATOR_NAME") as Rectangle;
         if (visualIndicator == null)
         {
             visualIndicator = new Rectangle();
             visualIndicator.Name = VISUAL_INDICATOR_NAME;
             visualIndicator.Height = listViewItemHighlighted.ActualHeight;
             visualIndicator.HorizontalAlignment = HorizontalAlignment.Left;
             visualIndicator.Width = VISUAL_INDICATOR_WIDTH;
             visualIndicator.Fill = LeftEdgeBrush;
             visualIndicator.Margin = new Thickness(-(listViewItemHighlighted.Padding.Left), 0, 0, 0);
             Panel panel = listViewItemHighlighted.ContentTemplateRoot as Panel;
             if (panel != null)
             {
                 if (panel is Grid)
                 {
                     visualIndicator.SetValue(Grid.RowSpanProperty, (panel as Grid).RowDefinitions.Count);
                 }
                 panel.Children.Add(visualIndicator);
             }
         }
         else
         {
             visualIndicator.Opacity = 1;
         }
     }
 }
Exemple #20
0
        private void CalculateRectangle(int input)
        {
            ClearGrid();

            int SqrtNumber = 0;
            int rowCount = 0;
            int columnCount = 0;

            SqrtNumber = Convert.ToInt32(Math.Sqrt(input));

            if (Math.Sqrt(input) > SqrtNumber)
            {
                SqrtNumber = SqrtNumber + 1;
                rowCount = SqrtNumber - 1;
            }
            else
                rowCount = SqrtNumber;


            columnCount = SqrtNumber;

            for (int column = 0; column < columnCount; column++)
            {
                myGrid.ColumnDefinitions.Add(new ColumnDefinition());
                myGrid.ColumnDefinitions[column].Width = GridLength.Auto;
            }

            for (int row = 0; row < rowCount; row++)
            {
                myGrid.RowDefinitions.Add(new RowDefinition());
                myGrid.RowDefinitions[row].Height = GridLength.Auto;
            }

            Rectangle rtn;
            int i = 0;

            for (int row = 0; row < myGrid.RowDefinitions.Count; row++)
            {
                for (int column = 0; column < myGrid.ColumnDefinitions.Count; column++)
                {
                    i++;
                    rtn = new Rectangle();
                    rtn.Width = 50;
                    rtn.Height = 50;
                    Thickness margin = rtn.Margin;
                    margin.Left = 1;
                    margin.Right = 1;
                    margin.Top = 1;
                    margin.Bottom = 1;
                    rtn.Margin = margin;
                    if ((i) > input)
                        rtn.Fill = Application.Current.Resources["LightPink"] as SolidColorBrush;
                    else
                        rtn.Fill = Application.Current.Resources["LightBlue"] as SolidColorBrush;

                    rtn.SetValue(Grid.ColumnProperty, column);
                    rtn.SetValue(Grid.RowProperty, row);
                    myGrid.Children.Add(rtn);
                }
            }

            var vm = (AlgorithmPageViewModel)DataContext;

            vm.RowCount = rowCount;
            vm.ColumnCount = columnCount;
            vm.BlankSpaceCount = i - input;
        }
        private DependencyObject CreatePin()
        {
            //Creating a Grid element.
            var myGrid = new Grid();
            myGrid.RowDefinitions.Add(new RowDefinition());
            myGrid.RowDefinitions.Add(new RowDefinition());
            myGrid.Background = new SolidColorBrush(Colors.Transparent);

            //Creating a Rectangle
            var myRectangle = new Rectangle {Fill = new SolidColorBrush(Colors.Black), Height = 20, Width = 20};
            myRectangle.SetValue(Grid.RowProperty, 0);
            myRectangle.SetValue(Grid.ColumnProperty, 0);

            //Adding the Rectangle to the Grid
            myGrid.Children.Add(myRectangle);

            //Creating a Polygon
            var myPolygon = new Polygon()
            {
                Points = new PointCollection() {new Point(2, 0), new Point(22, 0), new Point(2, 40)},
                Stroke = new SolidColorBrush(Colors.Black),
                Fill = new SolidColorBrush(Colors.Black)
            };
            myPolygon.SetValue(Grid.RowProperty, 1);
            myPolygon.SetValue(Grid.ColumnProperty, 0);

            //Adding the Polygon to the Grid
            myGrid.Children.Add(myPolygon);
            return myGrid;
        }
Exemple #22
0
        private void createGameGrid(int gridSize)
        {
            int cols, rows;
            // create row and col definitions
            for( cols=0; cols < gridSize; cols++)
            {
                contentGrid.RowDefinitions.Add(new RowDefinition());
                contentGrid.ColumnDefinitions.Add(new ColumnDefinition());
            }

            // add rectangle to the grid squares
            // make them a little smaller
            Rectangle myR;
            for (cols = 0; cols < gridSize; cols++)
            {
                for (rows = 0; rows < gridSize; rows++)
                {
                    myR = new Rectangle();
                    myR.Name = "r" + cols.ToString() + "_" + rows.ToString(); // r0_1
                    myR.Width = (contentGrid.Width / gridSize) - 4;
                    myR.Height = (contentGrid.Height / gridSize) - 4;
                    myR.HorizontalAlignment = HorizontalAlignment.Center;
                    myR.VerticalAlignment = VerticalAlignment.Center;
                    myR.SetValue(Grid.RowProperty, rows);
                    myR.SetValue(Grid.ColumnProperty, cols);
                    myR.Fill = new SolidColorBrush(Colors.LightGray);
                    myR.Tapped += MyR_Tapped;
                    contentGrid.Children.Add(myR);
                }
            }

            Ellipse myE;

            //TransformGroup myTransformGroup = new TransformGroup();
            //TranslateTransform transTransForm;
            //transTransForm = new TranslateTransform();
            //transTransForm.X = contentGrid.Width * ((gridSize - 1) / gridSize);
            //transTransForm.Y = contentGrid.Height* ((gridSize - 1) / gridSize);
            //transTransForm.SetValue(NameProperty, "myTranslateTransform");
            //myTransformGroup.Children.Add(transTransForm);

            for (cols = 0; cols < 2; cols++)
            {
                myE = new Ellipse();
                myE.Name = "piece" + cols.ToString();
                myE.Height = (contentGrid.Height / gridSize) - 6;
                myE.Width = (contentGrid.Width / gridSize) - 6;
                myE.Stroke = new SolidColorBrush(Colors.Red);
                myE.StrokeThickness = 0;
                myE.Fill = new SolidColorBrush(Colors.Yellow);

                myE.SetValue(Grid.RowProperty, cols);
                myE.SetValue(Grid.ColumnProperty, cols);
                myE.Tapped += MyE_Tapped;

                //myE.RenderTransform = myTransformGroup;

                _ellipseHeight = myE.Height;
                _ellipseWidth = myE.Width;

                contentGrid.Children.Add(myE);
            }
        }
        public static void DrawMap(Canvas canvas)
        {
            var blue = new SolidColorBrush(Colors.Blue);

            foreach (var rect in Map)
            {
                Rectangle rectangle = new Rectangle() { Width = rect.Width, Height = rect.Height };
                rectangle.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top;
                rectangle.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                rectangle.SetValue(Canvas.LeftProperty, rect.Left);
                rectangle.SetValue(Canvas.TopProperty, rect.Top);
                rectangle.Fill = blue;
                canvas.Children.Add(rectangle);
            }
        }