當前位置: 首頁>>代碼示例>>C#>>正文


C# Rectangle.SetBinding方法代碼示例

本文整理匯總了C#中System.Windows.Shapes.Rectangle.SetBinding方法的典型用法代碼示例。如果您正苦於以下問題:C# Rectangle.SetBinding方法的具體用法?C# Rectangle.SetBinding怎麽用?C# Rectangle.SetBinding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Shapes.Rectangle的用法示例。


在下文中一共展示了Rectangle.SetBinding方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Window

        public Window()
        {
            this.WindowStartUpLocation = WindowStartUpLocation.CenterScreen;

            rcBackground = new System.Windows.Shapes.Rectangle();
            rcBackground.StrokeThickness = 1;
            rcBackground.Parent = this;
            rcBackground.RadiusX = 0;
            rcBackground.RadiusY = 0;

            rcBackground.SetBinding (
                System.Windows.Shapes.Rectangle.FillProperty,
                new Binding("Background") {
                    Source = this,
                    Mode = BindingMode.OneWay,
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                });

            rcBackground.SetBinding (
                System.Windows.Shapes.Rectangle.StrokeProperty,
                new Binding("BorderBrush") {
                    Source = this,
                    Mode = BindingMode.OneWay,
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                });
        }
開發者ID:kimaina,項目名稱:WPFLight,代碼行數:26,代碼來源:Window.cs

示例2: SpriteElement

    public SpriteElement() {
      m_transform = new TranslateTransform();
      m_brush = new ImageBrush() { Stretch = Stretch.None, AlignmentX = AlignmentX.Left, AlignmentY = AlignmentY.Top, Transform = m_transform };

      var rect = new Rectangle() { Fill = m_brush };
      rect.SetBinding(Rectangle.WidthProperty, new Binding("SpriteWidth") { Source = this });
      rect.SetBinding(Rectangle.HeightProperty, new Binding("SpriteHeight") { Source = this });
      this.Content = rect;
    }
開發者ID:edealbag,項目名稱:bot,代碼行數:9,代碼來源:SpriteElement.cs

示例3: CreateWindowCommandRectangle

        /// <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;
        }
開發者ID:icygit,項目名稱:Orchestra,代碼行數:37,代碼來源:WindowCommandHelper.cs

示例4: CreateWorkspaceBackground

        private IEnumerable<UIElement> CreateWorkspaceBackground()
        {
            var back = new Rectangle();
            back.Fill = Brushes.Wheat;
            back.AllowDrop = true;
            back.Drop += workSpace_Drop_1;

            var widthBinding = new Binding()
            {
                RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Canvas), 1),
                Path = new PropertyPath("ActualWidth")
            };
            var heightBinding = new Binding()
            {
                RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Canvas), 1),
                Path = new PropertyPath("ActualHeight")
            };
            back.SetBinding(Rectangle.WidthProperty, widthBinding);
            back.SetBinding(Rectangle.HeightProperty, heightBinding);

            yield return back;
        }
開發者ID:tica,項目名稱:DataFlow,代碼行數:22,代碼來源:MainWindow.xaml.cs

示例5: createRectangle

        private Rectangle createRectangle(System.Windows.VerticalAlignment verticalAlignment, Brush color)
        {
            Rectangle r = new Rectangle();
            Binding widthBinding = new Binding("Width");
            widthBinding.Source = this;

            r = new Rectangle();
            r.DataContext = this;
            r.VerticalAlignment = verticalAlignment;

            r.Fill = color;
            r.SetBinding(Rectangle.WidthProperty, widthBinding);

            return r;
        }
開發者ID:hihack,項目名稱:CRM.Mobile,代碼行數:15,代碼來源:CRMScrollViewer.cs

示例6: OnGetLegendSymbol

        /// <inheritdoc/>
        protected override UIElement OnGetLegendSymbol()
        {
            var grid = new Grid
            {
                MinWidth = 16,
                MinHeight = 16,
            };

            var background = new Rectangle
            {
                Width = 16,
                Height = 16,
            };
            background.SetBinding(Shape.FillProperty, new Binding("Background") { Source = this });
            grid.Children.Add(background);
            return grid;
        }
開發者ID:Zolniu,項目名稱:DigitalRune,代碼行數:18,代碼來源:ChartBackground.cs

示例7: InitializeGrid

        private void InitializeGrid()
        {
            Trace.WriteLine("Initializing Grid");

            int numRows = this.ViewModel.GridWidth;
            int numCols = this.ViewModel.GridHeight;

            double cellWidth = this.gameOfLifeCanvas.Width / numCols;
            double cellHeight = this.gameOfLifeCanvas.Height / numRows;
            CellStateToBrushConverter cellStateToBrushConverter = new CellStateToBrushConverter();

            for (int columnIndex = 0; columnIndex < numCols; columnIndex++)
            {
                for (int rowIndex = 0; rowIndex < numRows; rowIndex++)
                {
                    Rectangle cellRect = new Rectangle
                        {
                            Width = cellWidth,
                            Height = cellHeight,
                            RenderTransform = new TranslateTransform(columnIndex * cellWidth, rowIndex * cellHeight),
                            RadiusX = cellWidth / 10,
                            RadiusY = cellHeight / 10
                        };

                    CellContainer cellContainer = new CellContainer(this.ViewModel[rowIndex, columnIndex]);
                    cellRect.InputBindings.Add(new MouseBinding(this.ViewModel.CellClickedCommand, new MouseGesture(MouseAction.LeftClick)) { CommandParameter = cellContainer });

                    cellRect.SetBinding(Shape.FillProperty, new Binding("State")
                        {
                            Source = cellContainer,
                            Mode = BindingMode.OneWay,
                            UpdateSourceTrigger = UpdateSourceTrigger.Explicit,
                            Converter = cellStateToBrushConverter
                        });

                    this.gameOfLifeCanvas.Children.Add(cellRect);
                }
            }

            Trace.WriteLine("Grid Initialized");
        }
開發者ID:taylan,項目名稱:vita,代碼行數:41,代碼來源:MainWindow.xaml.cs

示例8: build_gui

        private void build_gui()
        {
            this.DataContext = spectrum;

            Rectangle rect1 = new Rectangle();
            rect1.Width = 70;
            rect1.Height = 70;
            Binding bind_brush = new Binding("SpectrumBrush");
            rect1.SetBinding(Rectangle.FillProperty, bind_brush);

            StackPanel sp = new StackPanel();
            StackPanel sp1 = this.tb_slider("R", "Red:");
            StackPanel sp2 = this.tb_slider("G", "Green:");
            StackPanel sp3 = this.tb_slider("B", "Blue:");

            sp.Children.Add(sp1);
            sp.Children.Add(sp2);
            sp.Children.Add(sp3);

            Slider rainbow_slider = new Slider();
            rainbow_slider.Width = 300;
            rainbow_slider.Minimum = 0.0;
            rainbow_slider.Maximum = 1.0;
            rainbow_slider.Background = this.spectrum.rainbow_brush(new Point(0.0, 0.5), new Point(1.0, 0.5));
            Binding bind_rainbow = new Binding("RainbowValue");
            rainbow_slider.SetBinding(Slider.ValueProperty, bind_rainbow);

            StackPanel sp_color = new StackPanel();
            sp_color.Orientation = Orientation.Horizontal;
            sp_color.Height = 80;
            sp_color.Children.Add(rect1);
            sp_color.Children.Add(sp);

            StackPanel all = new StackPanel();
            all.Children.Add(sp_color);
            all.Children.Add(rainbow_slider);
            all.Height = 120;
            all.Width = 300;
            this.Content = all;
        }
開發者ID:mario007,項目名稱:renmas,代碼行數:40,代碼來源:SpectrumEditor.xaml.cs

示例9: OnApplyTemplate

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            Overlay = GetTemplateChild("Overlay") as Rectangle;
            if (Overlay != null)
            {
                // Tie the IsEnabled property to the visibility of the overlay rectangle (to give it a grayed out effect)
                Binding binding = new Binding()
                {
                    Source = this,
                    Path = new PropertyPath("IsEnabled"),
                    Converter = new ReverseVisibilityConverter(),
                };
                Overlay.SetBinding(Rectangle.VisibilityProperty, binding);
            }

            SymbolsList = GetTemplateChild("SymbolsList") as ItemsControl;
            if (SymbolsList != null)
            {
                SymbolsList.MouseLeftButtonUp += new MouseButtonEventHandler(Symbols_MouseLeftButtonUp);                
            }
        }
開發者ID:yulifengwx,項目名稱:arcgis-viewer-silverlight,代碼行數:23,代碼來源:MarkerSymbolSelector.cs

示例10: OnApplyTemplate

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            SampleSelector = GetTemplateChild(SampleSelectorName) as Grid;
            SelectedHueColor = GetTemplateChild(SelectedHueColorName) as Rectangle;

            var body = GetTemplateChild(BodyName) as Grid;

            if (body != null)
            {
                _monitor = new MovementMonitor();
                _monitor.Movement += _monitor_Movement;
                _monitor.MonitorControl(body);
            }

            ColorSlider = GetTemplateChild(ColorSliderName) as ColorSlider;

            if (ColorSlider != null)
            {
                if (Thumb == null)
                    Thumb = new ColorSliderThumb();

                ColorSlider.ColorChanged += ColorSlider_ColorChanged;

                if(SelectedHueColor != null)
                {
                    var binding = new System.Windows.Data.Binding
                                      {
                                          Source = ColorSlider,
                                          Path = new PropertyPath("SolidColorBrush"),
                                      };

                    SelectedHueColor.SetBinding(Shape.FillProperty, binding);
                }
            }
        }
開發者ID:phicuong08,項目名稱:coding4fun,代碼行數:37,代碼來源:ColorPicker.cs

示例11: AddFakeComponent

        private void AddFakeComponent(FrameworkElement control, object item)
        {
            if (control != null && item != null)
            {
                var fakeControl = new Rectangle();
                fakeControl.Tag = item;
                fakeControl.Fill = Brushes.Transparent;

                //InkCanvas.SetTop(fakeControl, item.Position.X);
                //InkCanvas.SetLeft(fakeControl, item.Position.Y);
                fakeControl.Width = control.ActualWidth;
                fakeControl.Height = control.ActualHeight;

                var positionBindingPrefix = "";
                if (typeof (DraggableComponent).IsAssignableFrom(item.GetType()))
                {
                    positionBindingPrefix = "Position.";
                }

                var leftBinding = new Binding(positionBindingPrefix + "X");
                leftBinding.Mode = BindingMode.TwoWay;
                leftBinding.Source = item;
                fakeControl.SetBinding(InkCanvas.LeftProperty, leftBinding);

                var rightBinding = new Binding(positionBindingPrefix + "Y");
                rightBinding.Mode = BindingMode.TwoWay;
                rightBinding.Source = item;
                fakeControl.SetBinding(InkCanvas.TopProperty, rightBinding);

                if (item.GetType() == typeof (TextFrame))
                {
                    var widthBinding = new Binding("Width");
                    widthBinding.Mode = BindingMode.TwoWay;
                    widthBinding.Source = item;
                    fakeControl.SetBinding(WidthProperty, widthBinding);

                    var heightBinding = new Binding("Height");
                    heightBinding.Mode = BindingMode.TwoWay;
                    heightBinding.Source = item;
                    fakeControl.SetBinding(HeightProperty, heightBinding);
                }
                else
                {
                    fakeControl.MinHeight = fakeControl.Height;
                    fakeControl.MinWidth = fakeControl.Width;
                    fakeControl.MaxHeight = fakeControl.Height;
                    fakeControl.MaxWidth = fakeControl.Width;
                }

                InkLayer.Children.Add(fakeControl);
            }
        }
開發者ID:aragoubi,項目名稱:Nine,代碼行數:52,代碼來源:LayerContainer.xaml.cs

示例12: ElementName_BeforeAddToTree_2

		public void ElementName_BeforeAddToTree_2 ()
		{
			var source = new Rectangle {
				Name = "Source",
				Width = 100,
			};
			var target = new Rectangle {
				Name = "Target"
			};

			target.SetBinding (Rectangle.WidthProperty, new Binding {
				ElementName = "Source",
				Path = new PropertyPath ("Width"),
				Mode = BindingMode.OneWay,
			});


			CreateAsyncTest (target,
				() => {
					TestPanel.Children.Add (source);
				}, () => {
					Assert.IsTrue (double.IsNaN (target.Width), "#1");
				}
			);
		}
開發者ID:shana,項目名稱:moon,代碼行數:25,代碼來源:BindingTest.cs

示例13: ElementName_AfterAddToTree

		public void ElementName_AfterAddToTree ()
		{
			var source = new Rectangle {
				Name = "Source",
				Width = 100,
			};
			var target = new Rectangle {
				Name = "Target"
			};

			target.SetBinding (Rectangle.WidthProperty, new Binding {
				ElementName = "Source",
				Path = new PropertyPath ("Width"),
				Mode = BindingMode.OneWay,
			});

			TestPanel.Children.Add (source);
			CreateAsyncTest (target, () => {
				Assert.AreEqual (100, target.Width, "#2");
			});
		}
開發者ID:shana,項目名稱:moon,代碼行數:21,代碼來源:BindingTest.cs

示例14: BindInheritedClass

		public void BindInheritedClass ()
		{
			InheritedData data = new InheritedData ();
			data.InnerData = new Data { Opacity = 1.0f };

			Rectangle rectangle = new Rectangle { Opacity = 0f };
			rectangle.DataContext = data;

			Binding binding = new Binding ("InnerData.Opacity");
			rectangle.SetBinding (Shape.OpacityProperty, binding);
			Assert.AreEqual (data.InnerData.Opacity, rectangle.Opacity, "#1");

			binding = new Binding ("Float");
			rectangle.SetBinding(Shape.OpacityProperty, binding);
		}
開發者ID:shana,項目名稱:moon,代碼行數:15,代碼來源:BindingTest.cs

示例15: ChangeSourceValue

		public void ChangeSourceValue()
		{
			Data data = new Data { Opacity = 0.5 };
			Rectangle r = new Rectangle();
			r.SetBinding(Rectangle.OpacityProperty, new Binding { Path = new PropertyPath("Opacity"), Source = data });
			Assert.AreEqual(data.Opacity, r.Opacity, "#1");
			data.Opacity = 0;
			Assert.AreNotEqual(data.Opacity, r.Opacity, "#2");
		}
開發者ID:shana,項目名稱:moon,代碼行數:9,代碼來源:BindingTest.cs


注:本文中的System.Windows.Shapes.Rectangle.SetBinding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。