本文整理汇总了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,
});
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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");
}
示例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;
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
示例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");
}
);
}
示例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");
});
}
示例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);
}
示例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");
}