本文整理汇总了C#中System.Windows.Controls.Canvas.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.SetBinding方法的具体用法?C# Canvas.SetBinding怎么用?C# Canvas.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Canvas
的用法示例。
在下文中一共展示了Canvas.SetBinding方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AngularGauge
/// <summary>
/// Initializes a new instance of the <see cref="AngularGauge"/> class.
/// </summary>
public AngularGauge()
{
Canvas = new Canvas();
Content = Canvas;
StickRotateTransform = new RotateTransform(180);
Stick = new Path
{
Data = Geometry.Parse("m0,90 a5,5 0 0 0 20,0 l-8,-88 a2,2 0 0 0 -4 0 z"),
Fill = Brushes.CornflowerBlue,
Stretch = Stretch.Fill,
RenderTransformOrigin = new Point(0.5, 0.9),
RenderTransform = StickRotateTransform
};
Canvas.Children.Add(Stick);
Panel.SetZIndex(Stick, 1);
Canvas.SetBinding(WidthProperty,
new Binding { Path = new PropertyPath(ActualWidthProperty), Source = this });
Canvas.SetBinding(HeightProperty,
new Binding { Path = new PropertyPath(ActualHeightProperty), Source = this });
SetCurrentValue(SectionsProperty, new List<AngularSection>());
SetCurrentValue(NeedleFillProperty, new SolidColorBrush(Color.FromRgb(69, 90, 100)));
Stick.SetBinding(Shape.FillProperty,
new Binding {Path = new PropertyPath(NeedleFillProperty), Source = this});
SetCurrentValue(AnimationsSpeedProperty, TimeSpan.FromMilliseconds(500));
SetCurrentValue(TicksForegroundProperty, new SolidColorBrush(Color.FromRgb(210, 210, 210)));
Func<double, string> defaultFormatter = x => x.ToString(CultureInfo.InvariantCulture);
SetCurrentValue(LabelFormatterProperty, defaultFormatter);
SetCurrentValue(LabelsEffectProperty,
new DropShadowEffect {ShadowDepth = 2, RenderingBias = RenderingBias.Performance});
SizeChanged += (sender, args) =>
{
IsControlLaoded = true;
Draw();
};
Slices = new Dictionary<AngularSection, PieSlice>();
}
示例2: LockMouseOutside
private void LockMouseOutside(bool doLock)
{
if (doLock)
{
Debug.Assert(WindowElement.ModalContainerPanel != null);
Binding wBinding = new Binding("ActualWidth");
Binding hBinding = new Binding("ActualHeight");
Canvas fence = new Canvas();
wBinding.Source = WindowElement.ModalContainerPanel;
hBinding.Source = WindowElement.ModalContainerPanel;
fence.SetBinding(Canvas.WidthProperty, wBinding);
fence.SetBinding(Canvas.HeightProperty, hBinding);
fence.Background = new SolidColorBrush(Color.FromArgb(141, 162, 174, 255));
fence.Opacity = 0.5;
WindowElement.ModalContainerPanel.Children.Add(this);
WindowElement.ModalContainerPanel.Children.Add(fence);
WindowElement.ModalContainerPanel.BringToBottom(fence);
WindowElement.ModalContainerPanel.Visibility = System.Windows.Visibility.Visible;
}
else
{
Debug.Assert(WindowElement.ModalContainerPanel != null);
for (int i = 0; i < WindowElement.ModalContainerPanel.Children.Count; i++)
{
UIElement target = WindowElement.ModalContainerPanel.Children[i];
if (target is Panel)
{
WindowElement.ModalContainerPanel.Children.Remove(target);
break;
}
}
WindowElement.ModalContainerPanel.Children.Remove(this);
WindowElement.ModalContainerPanel.Visibility = System.Windows.Visibility.Hidden;
}
}
示例3: HexGlyphMargin
public HexGlyphMargin(IMenuService menuService, WpfHexViewHost wpfHexViewHost, HexViewTagAggregatorFactoryService viewTagAggregatorFactoryService, HexEditorFormatMapService editorFormatMapService, Lazy<HexGlyphMouseProcessorProvider, IGlyphMouseProcessorProviderMetadata>[] glyphMouseProcessorProviders, Lazy<HexGlyphFactoryProvider, IGlyphMetadata>[] glyphFactoryProviders, HexMarginContextMenuService marginContextMenuHandlerProviderService) {
if (menuService == null)
throw new ArgumentNullException(nameof(menuService));
if (wpfHexViewHost == null)
throw new ArgumentNullException(nameof(wpfHexViewHost));
if (viewTagAggregatorFactoryService == null)
throw new ArgumentNullException(nameof(viewTagAggregatorFactoryService));
if (editorFormatMapService == null)
throw new ArgumentNullException(nameof(editorFormatMapService));
if (glyphMouseProcessorProviders == null)
throw new ArgumentNullException(nameof(glyphMouseProcessorProviders));
if (glyphFactoryProviders == null)
throw new ArgumentNullException(nameof(glyphFactoryProviders));
canvas = new Canvas();
glyphFactories = new Dictionary<Type, GlyphFactoryInfo>();
childCanvases = Array.Empty<Canvas>();
this.wpfHexViewHost = wpfHexViewHost;
this.viewTagAggregatorFactoryService = viewTagAggregatorFactoryService;
this.editorFormatMapService = editorFormatMapService;
lazyGlyphMouseProcessorProviders = glyphMouseProcessorProviders;
lazyGlyphFactoryProviders = glyphFactoryProviders;
var binding = new Binding {
Path = new PropertyPath(Panel.BackgroundProperty),
Source = canvas,
};
canvas.SetBinding(DsImage.BackgroundBrushProperty, binding);
wpfHexViewHost.HexView.Options.OptionChanged += Options_OptionChanged;
wpfHexViewHost.HexView.ZoomLevelChanged += HexView_ZoomLevelChanged;
canvas.IsVisibleChanged += GlyphMargin_IsVisibleChanged;
UpdateVisibility();
canvas.Width = MARGIN_WIDTH;
canvas.ClipToBounds = true;
menuService.InitializeContextMenu(VisualElement, new Guid(MenuConstants.GUIDOBJ_GLYPHMARGIN_GUID), marginContextMenuHandlerProviderService.Create(wpfHexViewHost, this, PredefinedHexMarginNames.Glyph), null, new Guid(MenuConstants.GLYPHMARGIN_GUID));
}
示例4: AdvancedContentPresenter
public AdvancedContentPresenter ()
{
Control = new ScrollViewer ();
ControlContainer = new Canvas ();
Scaling = new TranslateTransform ();
IsShiftAble = true;
Control.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
Control.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
ControlContainer.MouseLeftButtonDown += ContentEditor_MouseLeftButtonDown;
ControlContainer.MouseLeftButtonUp += ContentEditor_MouseLeftButtonUp;
ControlContainer.MouseMove += ContentEditor_MouseMove;
ControlContainer.RenderTransform = Scaling;
Control.PreviewMouseWheel += OuterContainer_MouseWheel;
Control.Content = ControlContainer;
ScaleFactor = 1;
TransformGroup group = new TransformGroup ();
Binding binding = new Binding ("ScaleFactor");
binding.Source = this;
ControlContainer.SetBinding (Canvas.TagProperty, binding);
ScaleTransform scaling = new ScaleTransform ();
BindingOperations.SetBinding (scaling, ScaleTransform.ScaleXProperty, binding);
BindingOperations.SetBinding (scaling, ScaleTransform.ScaleYProperty, binding);
group.Children.Add (scaling);
ControlContainer.LayoutTransform = group;
}
示例5: AddFreqGrid
//.........这里部分代码省略.........
grid.ColumnDefinitions.Add(column);
}
ColumnDefinition totalColumn = new ColumnDefinition();
totalColumn.Width = GridLength.Auto;
grid.ColumnDefinitions.Add(totalColumn);
ScrollViewer sv = new ScrollViewer();
sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
sv.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
sv.MaxHeight = System.Windows.SystemParameters.PrimaryScreenHeight - 320;
sv.MaxWidth = System.Windows.SystemParameters.PrimaryScreenWidth - 300;
sv.Margin = (Thickness)this.Resources["expanderMargin"];
Grid gridOuter = new Grid();
gridOuter.ColumnDefinitions.Add(new ColumnDefinition());
gridOuter.ColumnDefinitions.Add(new ColumnDefinition());
gridOuter.RowDefinitions.Add(new RowDefinition());
gridOuter.RowDefinitions.Add(new RowDefinition());
Grid.SetColumn(grid, 1);
Grid.SetRow(grid, 1);
gridOuter.Children.Add(grid);
Canvas exposureCanvas = new Canvas();
Grid.SetColumn(exposureCanvas, 0);
Grid.SetRow(exposureCanvas, 1);
exposureCanvas.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
exposureCanvas.VerticalAlignment = System.Windows.VerticalAlignment.Center;
exposureCanvas.Width = 25;
Binding canvasHeightBinding = new Binding("Height");
canvasHeightBinding.Source = grid;
exposureCanvas.SetBinding(Grid.HeightProperty, canvasHeightBinding);
TextBlock tblock1 = new TextBlock();
tblock1.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
tblock1.VerticalAlignment = System.Windows.VerticalAlignment.Center;
tblock1.Margin = new Thickness(0, 0, -5, 0);
tblock1.FontWeight = FontWeights.Bold;
tblock1.FontSize = tblock1.FontSize + 2;
if (DashboardHelper.GetAllGroupsAsList().Contains(cbxExposureField.SelectedItem.ToString()))
{
tblock1.Text = value;
}
else
{
tblock1.Text = cbxExposureField.SelectedItem.ToString();
}
Typeface typeFace = new Typeface(new FontFamily("Global User Interface"), tblock1.FontStyle, tblock1.FontWeight, tblock1.FontStretch);
FormattedText ftxt = new FormattedText(tblock1.Text, System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, typeFace, tblock1.FontSize, Brushes.Black);
RotateTransform rotate = new RotateTransform(270);
// This code works, but only if grid height is known at this point.
//double actualCanvasHeight = exposureCanvas.Height;
//double actualControlWidth = ftxt.Width;//tblockExposure.ActualWidth;
//double x = Canvas.GetLeft(tblock1);
//if (actualCanvasHeight > actualControlWidth)
//{
// double diff = actualCanvasHeight - actualControlWidth;
示例6: PathIsDot
public void PathIsDot ()
{
var target = new Canvas ();
target.DataContext = "5";
target.SetBinding (Canvas.WidthProperty, new Binding ("."));
Assert.AreEqual (5, target.Width, "#1");
}
示例7: GraphCanvas
//----------------------------------------------------------------------------//
// Constructors //
//----------------------------------------------------------------------------//
////////////////////////////////////////////////////////////////////////////////
/// <summary> </summary>
public GraphCanvas()
{
// Create brushes
mSourceBrush = new SolidColorBrush (Color.FromArgb (255, 32, 132, 32));
mTargetBrush = new SolidColorBrush (Color.FromArgb (255, 132, 32, 32));
// Create selection containers
mSelected = new LinkedList<Sensor>();
// Initialize lasso selection
mLassoCanvas = new Canvas();
Children.Add (mLassoCanvas);
mSelection = new LinkedList<Point>();
mLassoCanvas.Visibility = Visibility.Collapsed;
Canvas.SetLeft (mLassoCanvas, 0);
Canvas.SetTop (mLassoCanvas, 0);
Canvas.SetZIndex (mLassoCanvas, 1);
Binding wBinding = new Binding ("Width" ); wBinding.Source = this;
Binding hBinding = new Binding ("Height"); hBinding.Source = this;
mLassoCanvas.SetBinding (Canvas.WidthProperty, wBinding);
mLassoCanvas.SetBinding (Canvas.HeightProperty, hBinding);
mLassoBrush = new SolidColorBrush (Color.FromArgb (164, 255, 255, 255));
// Initialize path canvas
mPathCanvas = new Canvas();
Children.Add (mPathCanvas);
Canvas.SetLeft (mPathCanvas, 0);
Canvas.SetTop (mPathCanvas, 0);
Canvas.SetZIndex (mPathCanvas, 1);
mPathCanvas.SetBinding (Canvas.WidthProperty, wBinding);
mPathCanvas.SetBinding (Canvas.HeightProperty, hBinding);
mPathBrush = new SolidColorBrush (Color.FromArgb (192, 255, 255, 255));
// Subscribe to events
MouseUp += ActionMouseUp;
MouseDown += ActionMouseDown;
MouseMove += ActionMouseMove;
}
示例8: Gauge
public Gauge()
{
Canvas = new Canvas {ClipToBounds = true};
Content = Canvas;
PieBack = new PieSlice();
Pie = new PieSlice();
TitleTextBlock = new TextBlock();
MeasureTextBlock = new TextBlock();
LeftLabel = new TextBlock();
RightLabel = new TextBlock();
Canvas.Children.Add(PieBack);
Canvas.Children.Add(Pie);
Canvas.Children.Add(TitleTextBlock);
Canvas.Children.Add(MeasureTextBlock);
Canvas.Children.Add(RightLabel);
Canvas.Children.Add(LeftLabel);
Panel.SetZIndex(PieBack, 0);
Panel.SetZIndex(Pie, 1);
Canvas.SetBinding(WidthProperty,
new Binding {Path = new PropertyPath(WidthProperty), Source = this});
Canvas.SetBinding(HeightProperty,
new Binding {Path = new PropertyPath(HeightProperty), Source = this});
PieBack.SetBinding(Shape.FillProperty,
new Binding {Path = new PropertyPath(GaugeBackgroundProperty), Source = this});
PieBack.SetBinding(Shape.StrokeThicknessProperty,
new Binding {Path = new PropertyPath(StrokeThicknessProperty), Source = this});
PieBack.SetBinding(Shape.StrokeProperty,
new Binding {Path = new PropertyPath(StrokeProperty), Source = this});
Pie.SetBinding(Shape.StrokeThicknessProperty,
new Binding { Path = new PropertyPath(StrokeThicknessProperty), Source = this });
Pie.Stroke = Brushes.Transparent;
TitleTextBlock.SetBinding(TextBlock.TextProperty,
new Binding { Path = new PropertyPath(TitleProperty), Source = this });
SetValue(GaugeBackgroundProperty, new SolidColorBrush(Color.FromRgb(21, 101, 191)) {Opacity = .1});
SetValue(StrokeThicknessProperty, 0d);
SetValue(StrokeProperty, new SolidColorBrush(Color.FromRgb(222, 222, 222)));
SetValue(ToColorProperty, Color.FromRgb(100, 180, 245));
SetValue(FromColorProperty, Color.FromRgb(21, 101, 191));
SetValue(MinHeightProperty, 50d);
SetValue(MinWidthProperty, 80d);
SetValue(AnimationsSpeedProperty, TimeSpan.FromMilliseconds(800));
MeasureTextBlock.FontWeight = FontWeights.Bold;
IsNew = true;
SizeChanged += (sender, args) =>
{
IsChartInitialized = true;
Update();
};
}
示例9: GeoMap
/// <summary>
/// Initializes a new instance of the <see cref="GeoMap"/> class.
/// </summary>
public GeoMap()
{
Canvas = new Canvas();
Map = new Canvas();
Canvas.Children.Add(Map);
Content = Canvas;
Canvas.SetBinding(WidthProperty,
new Binding { Path = new PropertyPath(ActualWidthProperty), Source = this });
Canvas.SetBinding(HeightProperty,
new Binding { Path = new PropertyPath(ActualHeightProperty), Source = this });
Lands = new Dictionary<string, MapData>();
SetCurrentValue(DefaultLandFillProperty, new SolidColorBrush(Color.FromArgb(200,255,255,255)));
SetCurrentValue(LandStrokeProperty, new SolidColorBrush(Color.FromArgb(30, 55,55, 55)));
SetCurrentValue(LandStrokeThicknessProperty, 1.3d);
SetCurrentValue(AnimationsSpeedProperty, TimeSpan.FromMilliseconds(500));
SetCurrentValue(BackgroundProperty, new SolidColorBrush(Color.FromArgb(150, 96, 125, 138)));
SetCurrentValue(GradientStopCollectionProperty, new GradientStopCollection
{
new GradientStop(Color.FromArgb(100,2,119,188), 0d),
new GradientStop(Color.FromRgb(2,119,188), 1d),
});
SetCurrentValue(HeatMapProperty, new Dictionary<string, double>());
SetCurrentValue(GeoMapTooltipProperty, new DefaultGeoMapTooltip {Visibility = Visibility.Hidden});
Canvas.Children.Add(GeoMapTooltip);
SizeChanged += (sender, e) =>
{
Draw();
};
MouseWheel += (sender, e) =>
{
if (!EnableZoomingAndPanning) return;
e.Handled = true;
var rt = Map.RenderTransform as ScaleTransform;
var p = rt == null ? 1 : rt.ScaleX;
p += e.Delta > 0 ? .05 : -.05;
p = p < 1 ? 1 : p;
var o = e.GetPosition(this);
if (e.Delta > 0) Map.RenderTransformOrigin = new Point(o.X/ActualWidth,o.Y/ActualHeight);
Map.RenderTransform = new ScaleTransform(p, p);
};
MouseDown += (sender, e) =>
{
if (!EnableZoomingAndPanning) return;
DragOrigin = e.GetPosition(this);
};
MouseUp += (sender, e) =>
{
if (!EnableZoomingAndPanning) return;
var end = e.GetPosition(this);
var delta = new Point(DragOrigin.X - end.X, DragOrigin.Y - end.Y);
var l = Canvas.GetLeft(Map) - delta.X;
var t = Canvas.GetTop(Map) - delta.Y;
if (DisableAnimations)
{
Canvas.SetLeft(Map, l);
Canvas.SetTop(Map, t);
}
else
{
Map.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(l, AnimationsSpeed));
Map.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(t, AnimationsSpeed));
}
};
}
示例10: OnApplyTemplate
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_dgTrendPens = GetTemplateChild("dgTrendPens") as DataGrid;
if (_dgTrendPens != null)
{
UpdateDgPensColumnsVisibility();
}
_gTrendPresenters = (Grid) GetTemplateChild("gTrendPresenters");
if (_gTrendPresenters != null)
{
_gTrendPresenters.MouseLeftButtonDown += GTrendPresentersMouseLeftButtonDown;
_gTrendPresenters.MouseLeftButtonUp += GTrendPresentersMouseLeftButtonUp;
_gTrendPresenters.MouseMove += GTrendPresentersMouseMove;
}
_gVerticalAxes = (Grid)GetTemplateChild("gVerticalAxes");
_cVerticalAxes = (Canvas)GetTemplateChild("cVerticalAxes");
if (_cVerticalAxes != null)
{
_cVerticalAxes.SizeChanged += CVerticalAxesSizeChanged;
}
_cHorizontalAxes = (Canvas)GetTemplateChild("cHorizontalAxes");
if (_cHorizontalAxes != null)
{
_cHorizontalAxes.SizeChanged += CHorizontalAxesSizeChanged;
}
_spHorisontalAxes = (StackPanel)GetTemplateChild("spHorisontalAxes");
#region Slider
_slSlider = GetTemplateChild("slSlider") as Slider;
if (_slSlider != null)
{
var sliderBinding = new Binding("CursorPosition") { Source = this, Mode = BindingMode.TwoWay };
_slSlider.SetBinding(RangeBase.ValueProperty, sliderBinding);
}
_cdSliderOffset = (ColumnDefinition)GetTemplateChild("cdSliderOffset");
_gSlider = (Grid)GetTemplateChild("gSlider");
if (_gSlider != null)
_gSlider.SizeChanged += GSliderSizeChanged;
_cSlider = (Canvas)GetTemplateChild("cSlider");
if (_cSlider != null)
{
var presentersVisibilityBinding = new Binding("ShowCursorPresenters") { Source = this, Converter = new BooleanToVisibilityConverter() };
_cSlider.SetBinding(VisibilityProperty, presentersVisibilityBinding);
_cSlider.SizeChanged += CSliderSizeChanged;
}
_spSlider = (Panel)GetTemplateChild("spSlider");
UpdateSliderVisibility();
#endregion
#region SetPeriod
_popupPeriod = GetTemplateChild("popupPeriod") as Popup;
_tspSetPeriod = GetTemplateChild("tspSetPeriod") as TimeSpanPicker;
if (_popupPeriod != null && _tspSetPeriod != null)
{
_popupPeriod.Opened += PopupPeriodOpened;
_tspSetPeriod.KeyUp += TspSetPeriodKeyUp;
var bSetPeriod = GetTemplateChild("bSetPeriod") as Button;
if (bSetPeriod != null)
bSetPeriod.Click += BSetPeriodClick;
}
#endregion
#region SetTime
_popupTime = GetTemplateChild("popupTime") as Popup;
_dtpSetTime = GetTemplateChild("dtpSetTime") as DateTimePicker;
if (_popupTime != null && _dtpSetTime != null)
{
_popupTime.Opened += PopupTimeOpened;
_dtpSetTime.KeyUp += DtpSetTimeKeyUp;
var bSetTime = GetTemplateChild("bSetTime") as Button;
if (bSetTime != null)
{
bSetTime.Click += BSetTimeClick;
}
}
#endregion
}