Example #1
1
        public Meter8()
        {
            var borderBrush = new LinearGradientBrush();
            borderBrush.StartPoint = new Point();
            borderBrush.EndPoint = new Point(1d, 1d);
            borderBrush.GradientStops.Add(new GradientStop() { Color = Colors.White, Offset = 0d });
            borderBrush.GradientStops.Add(new GradientStop() { Color = Colors.White, Offset = 0.4999d });
            borderBrush.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(0xff, 0x84, 0x7B, 0x6C), Offset = 0.5d });
            borderBrush.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(0xff, 0x84, 0x7B, 0x6C), Offset = 1d });
            var border = new Rectangle();
            border.Fill = borderBrush;
            //border.Stroke = new SolidColorBrush(Colors.Black);
            //border.StrokeThickness = 1d;

            var background = new Rectangle();
            background.Fill = new SolidColorBrush(Color.FromArgb(0xff, 0xAD, 0xA7, 0x9D));
            background.Margin = new Thickness(4d);

            var grid = new Grid();
            grid.Children.Add(border);
            grid.Children.Add(background);
            grid.Children.Add(_canvas);
            grid.Children.Add(_calibrationCanvas);

            this.Content = grid;

            _label.Text = Value.ToString();
            _label.Foreground = new SolidColorBrush(ForeColor);

            _pointLine.Stroke = new SolidColorBrush(Colors.Red);
            _pointLine.StrokeThickness = 2d;
            this.SizeChanged += Meter_SizeChanged;
        }
        public WatchViewFullscreen()
        {
            InitializeComponent();

            MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(view_MouseButtonIgnore);
            MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(view_MouseButtonIgnore);
            MouseRightButtonUp += new System.Windows.Input.MouseButtonEventHandler(view_MouseRightButtonUp);
            PreviewMouseRightButtonDown += new System.Windows.Input.MouseButtonEventHandler(view_PreviewMouseRightButtonDown);

            MenuItem mi = new MenuItem();
            mi.Header = "Zoom to Fit";
            mi.Click += new RoutedEventHandler(mi_Click);

            MainContextMenu.Items.Add(mi);

            System.Windows.Shapes.Rectangle backgroundRect = new System.Windows.Shapes.Rectangle();
            Canvas.SetZIndex(backgroundRect, -10);
            backgroundRect.IsHitTestVisible = false;
            BrushConverter bc = new BrushConverter();
            Brush strokeBrush = (Brush)bc.ConvertFrom("#313131");
            backgroundRect.Stroke = strokeBrush;
            backgroundRect.StrokeThickness = 1;
            SolidColorBrush backgroundBrush = new SolidColorBrush(System.Windows.Media.Color.FromRgb(250, 250, 216));
            backgroundRect.Fill = backgroundBrush;

            inputGrid.Children.Add(backgroundRect);
        }
        public void boardCanvas_MouseDown(object sender, MouseButtonEventArgs e)
        {
            boardCanvas.CaptureMouse();
            sP = e.GetPosition(boardCanvas);
            newAtr.Color = (Color)colorStroke.SelectedColor;
            newAtr.Height = newAtr.Width = slider.Value;
            boardCanvas.DefaultDrawingAttributes = newAtr;

            if (tempTool == pencilImage.Name || tempTool == eraserImage.Name || tempTool == circleImage.Name || tempTool == rectangleImage.Name)
            {

               if (tempTool == circleImage.Name)
                {
                    ellipse = new Ellipse();
                }
                else if (tempTool == rectangleImage.Name)
                {
                    rect = new Rectangle();
                }
            }
            else if (tempTool == lineImage.Name)
            {
                line_C = new Line();
            }

            else if (tempTool == textBoxImage.Name) {
                tB = new TextBox();
            }

            //eP = new Point(0, 0);
        }
Example #4
1
        public static Uri Create(string filename, string text, SolidColorBrush backgroundColor, double textSize, Size size)
        {
            var background = new Rectangle();
            background.Width = size.Width;
            background.Height = size.Height;
            background.Fill = backgroundColor;

            var textBlock = new TextBlock();
            textBlock.Width = 500;
            textBlock.Height = 500;
            textBlock.TextWrapping = TextWrapping.Wrap;
            textBlock.Text = text;
            textBlock.FontSize = textSize;
            textBlock.Foreground = new SolidColorBrush(Colors.White);
            textBlock.FontFamily = new FontFamily("Segoe WP");

            var tileImage = "/Shared/ShellContent/" + filename;
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                var bitmap = new WriteableBitmap((int)size.Width, (int)size.Height);
                bitmap.Render(background, new TranslateTransform());
                bitmap.Render(textBlock, new TranslateTransform() { X = 39, Y = 88 });
                var stream = store.CreateFile(tileImage);
                bitmap.Invalidate();
                bitmap.SaveJpeg(stream, (int)size.Width, (int)size.Height, 0, 99);
                stream.Close();
            }
            return new Uri("ms-appdata:///local" + tileImage, UriKind.Absolute);
        }
Example #5
1
        //Constructeur
        public Brique(Grid parent, double posX, double posY, bool cassable)
        {
            //Création de l'ellipse
            this._forme = new Rectangle();

            //Ajout au parent
            parent.Children.Add(this._forme);

            //Taille de la Brique
            this._forme.Height = 20;
            this._forme.Width = 60;

            //Position de la Brique
            this._forme.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            this._forme.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            this._forme.Margin = new System.Windows.Thickness(posX, posY, 0, 0);

            this.Cassable = cassable;

            //Couleur de la Brique
            //Couleur de fond
            Thread.Sleep(1);
            Random R = new Random(unchecked((int)DateTime.Now.Ticks));
            SolidColorBrush couleurFond = new SolidColorBrush();
            byte Red = (byte)(R.Next(253) + 1);
            byte Green = (byte)(R.Next(253) + 1);
            byte Blue = (byte)(R.Next(253) + 1);
            //Noire si incassable
            couleurFond.Color = cassable ? Color.FromRgb(Red, Green, Blue) : Color.FromRgb(0, 0, 0);
            this._forme.Fill = couleurFond;
            //Couleur de bordure
            SolidColorBrush couleurBord = new SolidColorBrush();
            couleurBord.Color = Color.FromRgb(255, 255, 255);
            this._forme.Stroke = couleurBord;
        }
Example #6
1
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            Body = GetTemplateChild(BodyName) as Grid;
            Slider = GetTemplateChild(SliderName) as SuperSlider;

            if (Thumb == null)
                Thumb = new ColorSliderThumb();

            SelectedColor = GetTemplateChild(SelectedColorName) as Rectangle;
            
            SizeChanged += UserControl_SizeChanged;

            if (Slider != null)
            {
                Slider.ValueChanged += Slider_ValueChanged;

                if (Color.A == 0 && Color.R == 0 && Color.G == 0 && Color.B == 0)
                    Color = System.Windows.Media.Color.FromArgb(255, 6, 255, 0);
                else
                    UpdateLayoutBasedOnColor();
            }

			IsEnabledVisualStateUpdate();
        }
        private void PerformCaptureAnimation()
        {
            LoadingView.Text = "Processing ...";
            ShowLoadingView();

            curtain = new Rectangle();
            curtain.Fill = new SolidColorBrush(Colors.White);
            LayoutRoot.Children.Add(curtain);

            Storyboard animation = new Storyboard();
            Duration duration = new Duration(TimeSpan.FromSeconds(0.3));
            animation.Duration = duration;

            DoubleAnimation curtainAnimation = new DoubleAnimation();
            animation.Children.Add(curtainAnimation);
            curtainAnimation.Duration = duration;
            curtainAnimation.To = 0;
            curtainAnimation.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseIn };
            Storyboard.SetTarget(curtainAnimation, curtain);
            Storyboard.SetTargetProperty(curtainAnimation, new PropertyPath("Opacity"));

            animation.Completed += (sender, e) => {
                LayoutRoot.Children.Remove(curtain);
            };

            animation.Begin();
        }
Example #8
0
        public DragAdorner(UIElement owner, UIElement adornElement, bool useVisualBrush, double opacity)
            : base(owner)
        {
            this.owner  = owner;

            if (useVisualBrush)
            {
                VisualBrush brush   = new VisualBrush(adornElement);
                Rectangle   rect    = new Rectangle();

                brush.Opacity       = opacity;
                rect.RadiusX        = 3;
                rect.RadiusY        = 3;
                rect.Width          = adornElement.DesiredSize.Width;
                rect.Height         = adornElement.DesiredSize.Height;

                this.XCenter        = adornElement.DesiredSize.Width / 2;
                this.YCenter        = adornElement.DesiredSize.Height / 2;

                rect.Fill = brush;

                this.child = rect;
            }
            else
            {
                this.child = adornElement;
            }
        }
Example #9
0
        public Paper()
        {
            // paper properties
            Background = new SolidColorBrush(Colors.White);
            Cursor = Cursors.IBeam;

            // setup caret
            caret = new Rectangle();
            caret.Fill = new SolidColorBrush(Colors.Black);
            caret.Height = 12;
            caret.Width = 1;
            caret.Margin = new Thickness(-1, 0, 0, 0);

            // setup caret timer
            caretTimer = new DispatcherTimer();
            caretTimer.Interval = TimeSpan.FromSeconds(0.5);
            caretTimer.Tick += delegate { caret.Visibility = (caret.Visibility == Visibility.Visible || !ShowCaret) ? Visibility.Collapsed : Visibility.Visible; };
            caretTimer.Start();

            // setup highlighting indicies
            HighlightedBlocks = new List<Character>();
            HighlightFromIndex = new Index(0, 0);
            HighlightToIndex = new Index(0, 0);

            // events
            MouseLeftButtonDown += Paper_MouseLeftButtonDown;
            MouseLeftButtonUp += Paper_MouseLeftButtonUp;
        }
        private void PictureTangle(string state, int row, int colume)
        {
            
            Rectangle rectangle = new Rectangle();
            rectangle.StrokeThickness = 3;
            rectangle.Stroke = Brushes.Black;
            rectangle.RadiusX = 30;
            rectangle.RadiusY = 30;
            rectangle.Width = 100;
            rectangle.Height = 80;

            Label label = new Label();
            label.Margin = new Thickness(0);
            label.Width = 100;
            label.Height = 80;
            label.Content = state;
            label.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;
            label.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
            
            gridpic.Children.Add(rectangle);
            gridpic.Children.Add(label);

            Grid.SetRow(rectangle, row);
            Grid.SetColumn(rectangle, colume);

            Grid.SetRow(label, row);
            Grid.SetColumn(label, colume);
        }
Example #11
0
		public void TestImplicitStyleRectangle_styleInRectangleDictionary ()
		{
			Style rectStyle = new Style { TargetType = typeof (Rectangle) };
			Setter setter = new Setter (FrameworkElement.WidthProperty, 100.0);
			rectStyle.Setters.Add (setter);

			Rectangle r = new Rectangle ();

			Assert.IsTrue (Double.IsNaN (r.Width), "1");

			r.Resources.Add (typeof (Rectangle), rectStyle);

			Assert.AreEqual (100.0, r.Width, "2");

			CreateAsyncTest (r,  () => {
					Assert.AreEqual (100.0, r.Width, "3");

					//setter.Value = 200.0;
					//Assert.AreEqual (200.0, r.Width, "4");

					rectStyle.Setters.Remove (setter);

					Assert.AreEqual (100.0, r.Width, "5");
				});
		}
Example #12
0
        //============== Funções ====================================
        public void CriarProcesso(double top, double left)
        {
            Rectangle rectangle;
            rectangle = new Rectangle();
            Canvas.SetTop(rectangle, top);
            Canvas.SetLeft(rectangle, left);
            rectangle.Fill = System.Windows.Media.Brushes.White;
            rectangle.Height = 20;
            rectangle.Width = 40;
            rectangle.StrokeThickness = 2;
            rectangle.Stroke = System.Windows.Media.Brushes.Gray;
            

            for (int i = 0; i < Processos.Count; i++)
            {
                if (Processos[i].Left == left && Processos[i].Top == top)
                {
                    Label lbl = new Label();
                    lbl.Content = "P" + Processos[i].ID;
                    Canvas.SetLeft(lbl, left + 10);
                    Canvas.SetTop(lbl, top - 2);

                    rectangle.Name = ("P" + Processos[i].ID);
                    Elementos.Add(rectangle);

                    Elementos.Add(lbl);

                    Processos[i].Texto = lbl;
                    break;
                }
            }

        }
        private void DrawingArea_MouseDown(object sender, MouseButtonEventArgs e)
        {
            startingPoint = e.GetPosition(DrawingArea);
            if (currentState == drawingState.CreateNewBounds)
            {// Creating and tracking a new Rectangle
                toCreateRectangle = new System.Windows.Shapes.Rectangle();
                toCreateRectangle.Stroke = Brushes.Black;
                toCreateRectangle.Opacity = .25;
                toCreateRectangle.Fill = Brushes.RosyBrown;
                toCreateRectangle.StrokeThickness = 4;
                toCreateRectangle.MinWidth = 25;
                toCreateRectangle.MinHeight = 25;
                Canvas.SetLeft(toCreateRectangle, startingPoint.X);
                Canvas.SetTop(toCreateRectangle, startingPoint.Y);
                DrawingArea.Children.Add(toCreateRectangle);
            }
            if (currentState == drawingState.PanView)
            {
                HitTestResult result = VisualTreeHelper.HitTest(DrawingArea, startingPoint);
                if (result != null)
                {
                    if (result.VisualHit is Rectangle)
                    {
                        toCreateRectangle = (Rectangle)result.VisualHit;

                        double offSetX = Canvas.GetLeft(toCreateRectangle) - startingPoint.X;
                        double offSetY = Canvas.GetTop(toCreateRectangle) - startingPoint.Y;
                        startingPoint = new Point(offSetX, offSetY);
                    }
                }
            }
        }
Example #14
0
        public MainWindow()
        {
            InitializeComponent();

            imagen = new BitmapImage(new Uri(System.IO.Directory.GetCurrentDirectory() + @"\Imagenes\imagen.jpg"));
            Rectangle rectangle = new Rectangle();
            rectangle.Width = 500;
            rectangle.Height = 500;
            rectangle.Fill = new ImageBrush(imagen);

            tablero = new Tablero(3, 3, imagen);

            foreach (Pieza p in tablero.Piezas)
            {
                Rectangle r = new Rectangle();
                r.Width = Canvas.Width / tablero.Filas;
                r.Height = Canvas.Height / tablero.Columnas;
                r.Fill = new ImageBrush(p.Imagen);
                r.Stroke = new SolidColorBrush(Colors.Black);
                r.StrokeThickness = 1;
                r.SetValue(Canvas.LeftProperty, Convert.ToDouble(p.Columna * (Canvas.Width / tablero.Filas)));
                r.SetValue(Canvas.TopProperty, Convert.ToDouble(p.Fila * (Canvas.Height / tablero.Columnas)));
                Canvas.Children.Add(r);
            }
        }
Example #15
0
        /// <summary>
        /// Creates the window command rectangle.
        /// </summary>
        /// <param name="parentButton">The parent button.</param>
        /// <param name="style">The style.</param>
        /// <returns>Rectangle.</returns>
        public static Rectangle CreateWindowCommandRectangle(Button parentButton, string style)
        {
            Argument.IsNotNull(() => parentButton);
            Argument.IsNotNullOrWhitespace(() => style);

            var rectangle = new Rectangle
            {
                Width = 16d,
                Height = 16d,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Stretch = Stretch.UniformToFill
            };

            rectangle.SetBinding(Rectangle.FillProperty, new Binding("Foreground")
            {
                Source = parentButton
            });

            var application = Application.Current;
            if (application != null)
            {
                rectangle.OpacityMask = new VisualBrush
                {
                    //Stretch = Stretch.Fill,
                    Visual = application.FindResource(style) as Visual
                };
            }

            return rectangle;
        }
Example #16
0
        /// <summary>
        /// Initializes a new instance of AxisSection class
        /// </summary>
        public AxisSection()
        {
            _rectangle = new Rectangle();
            _label = new TextBlock();

            SetValue(StrokeProperty, new SolidColorBrush(Color.FromRgb(131, 172, 191)));
            SetValue(FillProperty, new SolidColorBrush(Color.FromRgb(131, 172, 191)) {Opacity = .35});
            SetValue(StrokeThicknessProperty, 0d);
            SetValue(FromValueProperty, 0d);
            SetValue(ToValueProperty, 0d);

            BindingOperations.SetBinding(_rectangle, Shape.FillProperty,
                    new Binding { Path = new PropertyPath(FillProperty), Source = this });
            BindingOperations.SetBinding(_rectangle, Shape.StrokeProperty,
                    new Binding { Path = new PropertyPath(StrokeProperty), Source = this });
            BindingOperations.SetBinding(_rectangle, Shape.StrokeDashArrayProperty,
                    new Binding { Path = new PropertyPath(StrokeDashArrayProperty), Source = this });
            BindingOperations.SetBinding(_rectangle, Shape.StrokeThicknessProperty,
                    new Binding { Path = new PropertyPath(StrokeThicknessProperty), Source = this });

            BindingOperations.SetBinding(_label, TextBlock.TextProperty,
                new Binding {Path = new PropertyPath(LabelProperty), Source = this});

            Panel.SetZIndex(_rectangle, -1);
        }
        private void SyncProperty()
        {
            _layoutRoot = FindName("LayoutRoot") as Canvas;
            _imageBorder = FindName("ImageBorder") as Rectangle;
            _mainImage = FindName("MainImage") as Image;
            _contentHolder = FindName("ContentHolder") as Canvas;
            _shadowCover = FindName("ShadowCover") as Rectangle;
            _fadeInStoryboard = FindName("FadeIn") as Storyboard;
            _fadeInShadowStory = FindName("FadeInShadow") as Storyboard;
            _fadeOutStoryboard = FindName("FadeOut") as Storyboard;
            _fadeOutStoryboard.Completed += new EventHandler(_fadeOutStoryboard_Completed);
            _fadeInShadowStory.Completed += new EventHandler(_fadeInShadowStory_Completed);

            _downloader = new Downloader();
            _downloader.DownloadFailed += new ErrorEventHandler(_downloader_DownloadFailed);
            _downloader.Completed += new EventHandler(_downloader_Completed);

            _imageTimer = new HtmlTimer();
            _imageTimer.Interval = 20;
            _imageTimer.Tick += new EventHandler(_imageTimer_Tick);

            _mainImage.MouseLeftButtonUp += new MouseEventHandler(_mainImage_MouseLeftButtonUp);
            _mainImage.Cursor = Cursors.Hand;

            // hide this instance.
            _imageBorder.Fill = null;
            _imageBorder.Stroke = null;

            // make event
            _mainImage.MouseEnter += new MouseEventHandler(_mainImage_MouseEnter);
            _mainImage.MouseLeave += new EventHandler(_mainImage_MouseLeave);
        }
 public void InitializeComponent()
 {
     if (!this._contentLoaded)
     {
         this._contentLoaded = true;
         Application.LoadComponent(this, new Uri("/TWC.OVP;component/Controls/ErrorMessageBox.xaml", UriKind.Relative));
         this.LayoutRoot = (Grid) base.FindName("LayoutRoot");
         this.DetailsEnabledStates = (VisualStateGroup) base.FindName("DetailsEnabledStates");
         this.ErrorMessageDetailDisabled = (VisualState) base.FindName("ErrorMessageDetailDisabled");
         this.ErrorMessageDetailEnabled = (VisualState) base.FindName("ErrorMessageDetailEnabled");
         this.DetailsStates = (VisualStateGroup) base.FindName("DetailsStates");
         this.DetailsVisible = (VisualState) base.FindName("DetailsVisible");
         this.DetailsNotVisible = (VisualState) base.FindName("DetailsNotVisible");
         this.BackgroundRectangle = (Rectangle) base.FindName("BackgroundRectangle");
         this.InnerDialogGrid = (Grid) base.FindName("InnerDialogGrid");
         this.DialogRectangle = (Rectangle) base.FindName("DialogRectangle");
         this.CloseButton = (Button) base.FindName("CloseButton");
         this.ErrorMessageTitleTextBlock = (TextBlock) base.FindName("ErrorMessageTitleTextBlock");
         this.ErrorMessageTextBlock = (TextBlock) base.FindName("ErrorMessageTextBlock");
         this.ButtonOK = (Button) base.FindName("ButtonOK");
         this.Icon = (TextBlock) base.FindName("Icon");
         this.SimpleErrorDetails = (Grid) base.FindName("SimpleErrorDetails");
         this.ShowDetailsToggle = (TextToggleButton) base.FindName("ShowDetailsToggle");
         this.DetailsTextBox = (TextBox) base.FindName("DetailsTextBox");
     }
 }
        public void Render()
        {
            NEATGenome genome = (NEATGenome)this.pop.BestGenome;
            Substrate substrate = SubstrateFactory.factorSandwichSubstrate(resolution, resolution);
            HyperNEATCODEC codec = new HyperNEATCODEC();
            NEATNetwork phenotype = (NEATNetwork)codec.Decode(this.pop, substrate, genome);

            TrialEvaluation trial = new TrialEvaluation(phenotype, this.testCase);
            IntPair actualPos = trial.Query(resolution);

            // clear what was there before
            GridCanvas.Children.Clear();

            //
            double boxWidth = GridCanvas.ActualWidth / resolution;
            double boxHeight = GridCanvas.ActualHeight / resolution;
            double delta = 2.0 / resolution;
            int index = 0;

            for (int row = 0; row < resolution; row++)
            {
                double y = -1 + (row * delta);
                double boxY = row * boxHeight;
                for (int col = 0; col < resolution; col++)
                {
                    double x = -1 + (col * delta);
                    double boxX = col * boxWidth;

                    Rectangle r = new Rectangle();
                    r.SetValue(Canvas.LeftProperty, boxX);
                    r.SetValue(Canvas.TopProperty, boxY);
                    r.Width = boxWidth;
                    r.Height = boxHeight;

                    if (this.testCase.GetPixel(x, y) > 0)
                    {
                        r.Fill = Brushes.Blue;
                    }
                    else
                    {
                        double d = trial.Output[index];
                        int c = trial.Normalize(d, 255);
                        SolidColorBrush b = new SolidColorBrush(Color.FromRgb(255, (byte)c, 255));
                        r.Fill = b;
                        r.Stroke = Brushes.Black;
                    }

                    GridCanvas.Children.Add(r);
                    index++;
                }
            }

            Rectangle target = new Rectangle();
            target.SetValue(Canvas.LeftProperty, actualPos.X * boxWidth);
            target.SetValue(Canvas.TopProperty, actualPos.Y * boxHeight);
            target.Width = boxWidth;
            target.Height = boxHeight;
            target.Fill = Brushes.Red;
            GridCanvas.Children.Add(target);
        }
Example #20
0
        // Return a HitType value to indicate what is at the point.
        private HitType SetHitType(Rectangle rect, Point point)
        {
            double left = Canvas.GetLeft(rect);
            double top = Canvas.GetTop(rect);
            double right = left + rect.Width;
            double bottom = top + rect.Height;
            if (point.X < left) return HitType.None;
            if (point.X > right) return HitType.None;
            if (point.Y < top) return HitType.None;
            if (point.Y > bottom) return HitType.None;

            const double GAP = 10;
            if (point.X - left < GAP)
            {
                // Left edge.
                if (point.Y - top < GAP) return HitType.UL;
                if (bottom - point.Y < GAP) return HitType.LL;
                return HitType.L;
            }
            if (right - point.X < GAP)
            {
                // Right edge.
                if (point.Y - top < GAP) return HitType.UR;
                if (bottom - point.Y < GAP) return HitType.LR;
                return HitType.R;
            }
            if (point.Y - top < GAP) return HitType.T;
            if (bottom - point.Y < GAP) return HitType.B;
            return HitType.Body;
        }
Example #21
0
		public void TestImplicitStyleRectangle_multipleImplicitStylesInVisualTree ()
		{
			Style rectStyle1 = new Style { TargetType = typeof (Rectangle) };
			Setter setter = new Setter (FrameworkElement.WidthProperty, 100.0);
			rectStyle1.Setters.Add (setter);

			Style rectStyle2 = new Style { TargetType = typeof (Rectangle) };
			setter = new Setter (FrameworkElement.HeightProperty, 100.0);
			rectStyle2.Setters.Add (setter);

			Rectangle r = new Rectangle ();
			r.Resources.Add (typeof (Rectangle), rectStyle1);

			Canvas c = new Canvas ();
			c.Resources.Add (typeof (Rectangle), rectStyle2);

			c.Children.Add (r);

			Assert.IsTrue (Double.IsNaN (r.Height), "1");

			CreateAsyncTest (c,  () => {
					Assert.AreEqual (100.0, r.Width, "2");
					Assert.IsTrue (Double.IsNaN (r.Height), "3");

					r.Resources.Remove (typeof (Rectangle));

					Assert.AreEqual (100.0, r.Height, "4");
					Assert.IsTrue (Double.IsNaN (r.Width), "5");
				});
		}
Example #22
0
        void AllSprites_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) {
                Sprite a = this.Instance.NewestSprite();
                var newRectangle = new Rectangle() {
                    Width = a.Width,
                    Height = a.Height,
                    Fill = a.Brush,
                    Tag = a
                };
                Canvas.SetTop(newRectangle, a.ScreenY());
                Canvas.SetLeft(newRectangle, a.ScreenX());
                newRectangle.MouseRightButtonDown += newRectangle_MouseRightButtonDown;
                this.canvas.Children.Add(newRectangle);
                if (this.cp != null) {
                    this.cp.livingSprites.ItemsSource = this.Instance.GetAllSprites().ToList();
                }
            } else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove) {
                var idx = e.OldStartingIndex;
                Dispatcher.Invoke((Action)(() =>
                    {
                        this.canvas.Children.RemoveAt(idx);
                        if (this.cp != null) {
                            this.cp.livingSprites.ItemsSource = this.Instance.GetAllSprites().ToList();
                        }
                    }));

            } else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset) {
                this.canvas.Children.Clear();
                if (this.cp != null) {
                    this.cp.livingSprites.ItemsSource = this.Instance.GetAllSprites().ToList();
                }
            }
        }
Example #23
0
 private void Button_Loaded(object sender, RoutedEventArgs args)
 {
     System.Windows.Controls.Button button = sender as System.Windows.Controls.Button;
     if (button != null)
     {
         StackPanel panel = new StackPanel()
         {
             Orientation = Orientation.Horizontal
         };
         Image shield = new Image()
         {
             Width = 24,
             Source = Shield
         };
         panel.Children.Add(shield);
         Rectangle rect = new Rectangle()
         {
             Width = 10
         };
         panel.Children.Add(rect);
         TextBlock text = new TextBlock()
         {
             Text = (button.Command as RoutedUICommand).Text
         };
         panel.Children.Add(text);
         button.Content = panel;
     }
 }
 public structRectangle() {
     rect = new Rectangle();
     beginTime = new TimeSpan();
     handState = new HandState();
     position = "";
     gestureTried = false;
 }
        public ColorGridBox()
        {
            // Define the ItemsPanel template.
            FrameworkElementFactory factoryUnigrid =
                            new FrameworkElementFactory(typeof(UniformGrid));
            factoryUnigrid.SetValue(UniformGrid.ColumnsProperty, 8);
            ItemsPanel = new ItemsPanelTemplate(factoryUnigrid);

            // Add items to the ListBox.
            foreach (string strColor in strColors)
            {
                // Create Rectangle and add to ListBox.
                Rectangle rect = new Rectangle();
                rect.Width = 12;
                rect.Height = 12;
                rect.Margin = new Thickness(4);
                rect.Fill = (Brush)
                    typeof(Brushes).GetProperty(strColor).GetValue(null, null);
                Items.Add(rect);

                // Create ToolTip for Rectangle.
                ToolTip tip = new ToolTip();
                tip.Content = strColor;
                rect.ToolTip = tip;
            }
            // Indicate that SelectedValue is Fill property of Rectangle item.
            SelectedValuePath = "Fill";
        }
Example #26
0
        public void CustomDataTemplate()
        {
            MyControl c = (MyControl)XamlReader.Load(@"
<x:MyControl xmlns=""http://schemas.microsoft.com/client/2007""
			xmlns:x=""clr-namespace:MoonTest.System.Windows;assembly=moon-unit"">
	<x:MyControl.ContentTemplate>
		<x:MyDataTemplate>
			<Rectangle />
		</x:MyDataTemplate>
	</x:MyControl.ContentTemplate>
</x:MyControl>");
            Rectangle r = new Rectangle();
            c.Content = r;
            c.ApplyTemplate();

            // Check that the visual tree matches up:
            // MyControl->ContentPresenter->Rectangle
            CreateAsyncTest(c,
                () =>
                {
                    Assert.VisualChildren(c,
                        new VisualNode<ContentPresenter>("#1",
                            new VisualNode<Rectangle>("#2")
                        )
                    );
                }
            );
        }
Example #27
0
		public override void OnApplyTemplate() {
			base.OnApplyTemplate();

			_spectrumDisplay = (Rectangle)GetTemplateChild("PART_SpectrumDisplay");
			CreateSpectrum();
			OnValueChanged(Double.NaN, Value);
		}
        public DragAdorner(UIElement owner, UIElement adornElement, bool useVisualBrush, double opacity)
            : base(owner)
        {
            System.Diagnostics.Debug.Assert(owner != null);
            System.Diagnostics.Debug.Assert(adornElement != null);
            _owner = owner;
            if (useVisualBrush)
            {
                VisualBrush _brush = new VisualBrush(adornElement);
                _brush.Opacity = opacity;
                Rectangle r = new Rectangle();
                r.RadiusX = 3;
                r.RadiusY = 3;

                //TODO: questioning DesiredSize vs. Actual 
                r.Width = adornElement.DesiredSize.Width;
                r.Height = adornElement.DesiredSize.Height;

                XCenter = adornElement.DesiredSize.Width / 2;
                YCenter = adornElement.DesiredSize.Height / 2;

                r.Fill = _brush;
                _child = r;

            }
            else
                _child = adornElement;


        }
        public TileRenderer(Canvas canvas, string displayText, Tile tile)
        {
            Tile = tile;
            AnimationTime = TimeSpan.FromSeconds(0.25);
            this.canvas = canvas;
            Width = DefaultWidth;
            Height = DefaultHeight;
            rectangle = new Rectangle
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                Stroke = new SolidColorBrush(Colors.Black),
                Fill = new SolidColorBrush(Colors.WhiteSmoke)
            };
            Children.Add(rectangle);

            text = new TextBlock
            {
                Text = displayText,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                TextAlignment = TextAlignment.Center,
                FontSize = 36,
                FontWeight = FontWeights.Bold,
                VerticalAlignment = VerticalAlignment.Top,
                Margin = new Thickness(0, 26, 0, 26)

            };

            Children.Add(text);
            canvas.Children.Add(this);
            SetPosition();
            tile.PositionChanged += UpdatePosition;
        }
        /// <summary>
        /// Draws the bone.
        /// </summary>
        /// <param name="trackedJoint1">The tracked joint1.</param>
        /// <param name="trackedJoint2">The tracked joint2.</param>
        /// 
        void drawBone(Joint trackedJoint1, Joint trackedJoint2)
        {
            Line bone = new Line();
            bone.Stroke = Brushes.Red;
            bone.StrokeThickness = 3;
            Point joint1 = this.ScalePosition(trackedJoint1.Position);
            bone.X1 = joint1.X;
            bone.Y1 = joint1.Y;

            Point mappedPoint1 = this.ScalePosition(trackedJoint1.Position);
            Rectangle r = new Rectangle(); r.Height = 10; r.Width = 10;
            r.Fill = Brushes.Red;
            Canvas.SetLeft(r, mappedPoint1.X - 2);
            Canvas.SetTop(r, mappedPoint1.Y - 2);
            this.caller.myCanvas.Children.Add(r);

            Point joint2 = this.ScalePosition(trackedJoint2.Position);
            bone.X2 = joint2.X;
            bone.Y2 = joint2.Y;

            Point mappedPoint2 = this.ScalePosition(trackedJoint2.Position);

            if (LeafJoint(trackedJoint2))
            {
                Rectangle r1 = new Rectangle(); r1.Height = 10; r1.Width = 10;
                r1.Fill = Brushes.Red;
                Canvas.SetLeft(r1, mappedPoint2.X - 2);
                Canvas.SetTop(r1, mappedPoint2.Y - 2);
                this.caller.myCanvas.Children.Add(r1);
                Point mappedPoint = this.ScalePosition(trackedJoint2.Position);

            }

            this.caller.myCanvas.Children.Add(bone);
        }