本文整理汇总了C#中ContentControl.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# ContentControl.SetBinding方法的具体用法?C# ContentControl.SetBinding怎么用?C# ContentControl.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContentControl
的用法示例。
在下文中一共展示了ContentControl.SetBinding方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectedItemBinding
public void SelectedItemBinding()
{
OverriddenAutoCompleteBox acb = new OverriddenAutoCompleteBox();
acb.ItemsSource = "words go here".Split();
ContentControl cc = new ContentControl();
Binding b = new Binding("SelectedItem");
b.Source = acb;
cc.SetBinding(ContentControl.ContentProperty, b);
int loadedCount = 0;
acb.Loaded += (o, e) => loadedCount++;
cc.Loaded += (o, e) => loadedCount++;
EnqueueCallback(() => TestPanel.Children.Add(acb));
EnqueueCallback(() => TestPanel.Children.Add(cc));
EnqueueConditional(() => 2 == loadedCount);
EnqueueCallback(() => acb.TextBox.Text = "w");
EnqueueConditional(() => acb.IsDropDownOpen);
EnqueueCallback(() => OverriddenSelectionAdapter.Current.SelectFirst());
EnqueueCallback(() => Assert.AreEqual("words", acb.SelectedItem));
EnqueueCallback(() => OverriddenSelectionAdapter.Current.TestCommit());
EnqueueConditional(() => !acb.IsDropDownOpen);
EnqueueCallback(() => Assert.AreEqual("words", cc.Content));
EnqueueTestComplete();
}
示例2: SelectedItemBinding
public void SelectedItemBinding()
{
TreeView treeView = new TreeView();
treeView.ItemsSource = "some test text".Split();
ContentControl contentControl = new ContentControl();
Binding binding = new Binding("SelectedItem");
binding.Source = treeView;
contentControl.SetBinding(ContentControl.ContentProperty, binding);
StackPanel panel = new StackPanel();
panel.Children.Add(treeView);
panel.Children.Add(contentControl);
TreeViewItem treeViewItem = null;
TestAsync(
panel,
() => treeViewItem = ((TreeViewItem)(treeView.ItemContainerGenerator.ContainerFromIndex(1))),
() => treeViewItem.IsSelected = true,
() => Assert.AreEqual("test", treeView.SelectedItem),
() => Assert.AreEqual("test", contentControl.Content));
}
示例3: GetLabelElement
internal ContentControl GetLabelElement()
{
LabelElement = new ContentControl();
Binding templateBinding = new Binding();
templateBinding.Source = this;
templateBinding.Path = new PropertyPath("LabelTemplate");
LabelElement.SetBinding(ContentControl.ContentTemplateProperty, templateBinding);
Binding contentBinding = new Binding();
contentBinding.Source = this;
contentBinding.Path = new PropertyPath("Text");
LabelElement.SetBinding(ContentControl.ContentProperty, contentBinding);
return LabelElement;
}
示例4: Initialize
private void Initialize()
{
double desiredWidth = 0;
CalculateAutoInterval();
GenerateLabels();
if (this.ActualHeight > 0 && this.ActualWidth > 0)
{
this.Children.Clear();
double yAxisHeightStep = this.ActualHeight / ((MIntervalCount > 0) ? MIntervalCount : 1);
double yAxisHeightPosition = this.DataToPoint(MStartValue);
Rect oldRect = new Rect(0, 0, 0, 0);
AxisLine = new Line();
Binding binding = new Binding();
binding.Path = new PropertyPath("AxisLineStyle");
binding.Source = this;
AxisLine.SetBinding(Line.StyleProperty, binding);
AxisLine.X1 = this.ActualWidth;
AxisLine.X2 = this.ActualWidth;
AxisLine.Y1 = 0;
AxisLine.Y2 = this.ActualHeight;
AxisLine.Measure(new Size(this.ActualHeight, this.ActualWidth));
Labels = new List<ContentControl>();
MajorTickLines = new List<Line>();
MinorTickLines = new List<Line>();
double labelSize = 0;
for (int i = this.MLabels.Count - 1; i >= 0; i--)
{
ContentControl label = new ContentControl();
label.Content = MLabels[i];
//label.ContentTemplate = this.LabelTemplate;
Binding labelTemplateBinding = new Binding();
labelTemplateBinding.Path = new PropertyPath("LabelTemplate");
labelTemplateBinding.Source = this;
label.SetBinding(ContentControl.ContentTemplateProperty, labelTemplateBinding);
label.Measure(new Size(this.ActualHeight, this.ActualWidth));
RotateTransform labelRotation = new RotateTransform();
labelRotation.Angle = LabelAngle;
Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation);
label.RenderTransform = labelRotation;
Labels.Add(label);
Line tickLine = new Line();
double labelPadding = 0;
Binding styleBinding = new Binding();
styleBinding.Path = new PropertyPath("MajorLineStyle");
styleBinding.Source = this;
tickLine.SetBinding(Line.StyleProperty, styleBinding);
//tickLine.Style = MajorLineStyle;
tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth));
tickLine.Y1 = yAxisHeightPosition;
tickLine.Y2 = yAxisHeightPosition;
switch (MajorTicksPosition)
{
case TickPosition.Inside:
tickLine.X1 = this.ActualWidth;
tickLine.X2 = tickLine.X1 + MajorLineSize;
if (this.ShowMajorTicks)
{
labelPadding = 0;
desiredWidth = 0;
}
break;
case TickPosition.Cross:
tickLine.X1 = this.ActualWidth -(MajorLineSize / 2);
tickLine.X2 = this.ActualWidth + (MajorLineSize / 2);
if (this.ShowMajorTicks)
{
labelPadding = tickLine.X2;
desiredWidth = this.MajorLineSize / 2;
}
break;
case TickPosition.Outside:
tickLine.X1 = this.ActualWidth;
tickLine.X2 = tickLine.X1 - MajorLineSize;
if (this.ShowMajorTicks)
{
labelPadding = tickLine.X2;
desiredWidth = this.MajorLineSize;
}
break;
default:
break;
}
Binding ticklineVisibilityBinding = new Binding();
ticklineVisibilityBinding.Path = new PropertyPath("ShowMajorTicks");
ticklineVisibilityBinding.Source = this;
ticklineVisibilityBinding.Converter = new BooleanToVisibilityConverter();
tickLine.SetBinding(Line.VisibilityProperty, ticklineVisibilityBinding);
MajorTickLines.Add(tickLine);
this.Children.Add(tickLine);
//desiredWidth = 0;
double minorstep = 0;
if (!(i == 0))
{
double minorWidth = yAxisHeightStep;
minorstep = minorWidth / (MinorTicksCount + 1);
for (int j = 0; j < this.MinorTicksCount; j++)
{
//.........这里部分代码省略.........
示例5: Update
/// <summary>
/// Updates this instance.
/// </summary>
internal void Update()
{
double desiredWidth = 0;
CalculateAutoInterval();
GenerateLabels();
if (this.ActualHeight > 0 && this.ActualWidth > 0)
{
double yAxisHeightStep = this.ActualHeight / ((MIntervalCount > 0) ? MIntervalCount : 1);
double yAxisHeightPosition = 0;
Rect oldRect = new Rect(0, 0, 0, 0);
AxisLine.X1 = this.ActualWidth;
AxisLine.X2 = this.ActualWidth;
AxisLine.Y1 = 0;
AxisLine.Y2 = this.ActualHeight;
Binding binding = new Binding();
binding.Path = new PropertyPath("AxisLineStyle");
binding.Source = this;
AxisLine.SetBinding(Line.StyleProperty, binding);
double labelSize = 0;
int minorCount = 0;
if (this.MLabels.Count == Labels.Count)
{
for (int i = this.MLabels.Count - 1; i >=0; i--)
{
yAxisHeightPosition = this.DataToPoint(MLabelValues[i]);
ContentControl label = Labels[i];
label.Content = MLabels[i];
label.Measure(new Size(this.ActualHeight, this.ActualWidth));
RotateTransform labelRotation = new RotateTransform();
labelRotation.Angle = LabelAngle;
Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation);
label.RenderTransform = labelRotation;
Line tickLine = MajorTickLines[i];
double labelPadding = 0;
tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth));
//tickLine.X1 = this.ActualWidth;
tickLine.Y1 = yAxisHeightPosition;
tickLine.Y2 = yAxisHeightPosition;
//tickLine.X2 = tickLine.X1 - MajorLineSize;
switch (MajorTicksPosition)
{
case TickPosition.Inside:
tickLine.X1 = this.ActualWidth;
tickLine.X2 = tickLine.X1 + MajorLineSize;
if (this.ShowMajorTicks)
{
labelPadding = 0;
desiredWidth = 0;
}
break;
case TickPosition.Cross:
tickLine.X1 = this.ActualWidth - (MajorLineSize / 2);
tickLine.X2 = this.ActualWidth + (MajorLineSize / 2);
if (this.ShowMajorTicks)
{
labelPadding = tickLine.X2;
desiredWidth = this.MajorLineSize / 2;
}
break;
case TickPosition.Outside:
tickLine.X1 = this.ActualWidth;
tickLine.X2 = tickLine.X1 - MajorLineSize;
if (this.ShowMajorTicks)
{
labelPadding = tickLine.X2;
desiredWidth = this.MajorLineSize;
}
break;
default:
break;
}
//desiredWidth = 0;
if (i != 0)
{
double minorWidth = yAxisHeightStep;
double minorstep = minorWidth / (MinorTicksCount + 1);
for (int j = 0; j < this.MinorTicksCount; j++)
{
Line minorLine = MinorTickLines[minorCount];
minorLine.Y1 = (yAxisHeightPosition + minorstep * (j + 1));
minorLine.Y2 = (yAxisHeightPosition + minorstep * (j + 1));
//minorLine.X1 = this.ActualWidth - (minorLine.StrokeThickness);
// minorLine.X2 = minorLine.X1 - MinorLineSize;
switch (MinorTicksPosition)
{
case TickPosition.Inside:
minorLine.X1 = this.ActualWidth;
minorLine.X2 = minorLine.X1 + MinorLineSize;
break;
case TickPosition.Cross:
minorLine.X1 = this.ActualWidth - (MinorLineSize / 2);
minorLine.X2 = this.ActualWidth + (MinorLineSize / 2);
break;
case TickPosition.Outside:
minorLine.X1 = this.ActualWidth;
minorLine.X2 = minorLine.X1 - MinorLineSize;
break;
//.........这里部分代码省略.........
示例6: Update
//.........这里部分代码省略.........
}
//Canvas.SetLeft(label, xAxisWidthPosition - (label.DesiredSize.Width / 2));
//Canvas.SetTop(label, desiredHeight);
if (this.LabelAngle == 0)
{
Canvas.SetLeft(label, xAxisWidthPosition - (label.DesiredSize.Width / 2));
Canvas.SetTop(label, desiredHeight);
labelSize = Math.Max(labelSize, label.DesiredSize.Height);
}
else
{
Canvas.SetLeft(label, xAxisWidthPosition - (rotatedRect.Width / 2) - rotatedRect.X);
Canvas.SetTop(label, desiredHeight - rotatedRect.Y);
labelSize = Math.Max(labelSize, rotatedRect.Height);
}
k++;
}
}
else
{
if (this.MLabels.Count > Labels.Count)
{
int offset = this.MLabels.Count - Labels.Count;
for (int j = 0; j < offset; j++)
{
ContentControl label = new ContentControl();
label.Content = MLabels[this.MLabels.Count - offset - 1];
Binding labelTemplateBinding = new Binding();
labelTemplateBinding.Path = new PropertyPath("LabelTemplate");
labelTemplateBinding.Source = this;
label.SetBinding(ContentControl.ContentTemplateProperty, labelTemplateBinding);
label.Measure(new Size(this.ActualHeight, this.ActualWidth));
RotateTransform labelRotation = new RotateTransform();
labelRotation.Angle = LabelAngle;
Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation);
// label.RenderTransformOrigin = new Point(0.5, 0.5);
label.RenderTransform = labelRotation;
Labels.Add(label);
Line tickLine = new Line();
Binding styleBinding = new Binding();
styleBinding.Path = new PropertyPath("MajorLineStyle");
styleBinding.Source = this;
tickLine.SetBinding(Line.StyleProperty, styleBinding);
tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth));
tickLine.X1 = xAxisWidthPosition - (tickLine.DesiredSize.Width / 2);
tickLine.X2 = xAxisWidthPosition - (tickLine.DesiredSize.Width / 2);
switch (this.MajorTicksPosition)
{
case TickPosition.Inside:
tickLine.Y1 = 0;
Binding tickSizeInsideBinding = new Binding();
tickSizeInsideBinding.Path = new PropertyPath("MajorLineSize");
tickSizeInsideBinding.Source = this;
tickSizeInsideBinding.Converter = new NegativeConverter();
tickLine.SetBinding(Line.Y2Property, tickSizeInsideBinding);
if (this.ShowMajorTicks)
{
desiredHeight = 0;
}
break;
case TickPosition.Cross:
Binding tickSizeNegativeCrossBinding = new Binding();
示例7: Initialize
/// <summary>
/// Initializes this instance.
/// </summary>
internal void Initialize()
{
double desiredHeight = 0;
double labelSize = 0;
//if (m_MinValue == m_startValue + m_Interval)
CalculateAutoInterval();
GenerateLabels();
if (this.ActualHeight > 0 && this.ActualWidth > 0)
{
this.Children.Clear();
double xAxisWidthStep = this.ActualWidth / ((MIntervalCount > 0) ? MIntervalCount : 1);
double xAxisWidthPosition = this.DataToPoint(MStartValue);
double minorstep = 0;
//m_offset = this.DataToPoint(m_MinValue + m_Interval);
Rect oldRect = new Rect(0, 0, 0, 0);
AxisLine = new Line();
AxisLine.X1 = 0;
AxisLine.X2 = this.ActualWidth;
AxisLine.Y1 = 0;
AxisLine.Y2 = 0;
Binding binding = new Binding();
binding.Path = new PropertyPath("AxisLineStyle");
binding.Source = this;
AxisLine.SetBinding(Line.StyleProperty, binding);
Labels = new List<ContentControl>();
MajorTickLines = new List<Line>();
MinorTickLines = new List<Line>();
for (int i = 0; i < this.MLabels.Count; i++)
{
ContentControl label = new ContentControl();
label.Content = MLabels[i];
Binding labelTemplateBinding = new Binding();
labelTemplateBinding.Path = new PropertyPath("LabelTemplate");
labelTemplateBinding.Source = this;
label.SetBinding(ContentControl.ContentTemplateProperty, labelTemplateBinding);
label.Measure(new Size(this.ActualHeight, this.ActualWidth));
RotateTransform labelRotation = new RotateTransform();
labelRotation.Angle = LabelAngle;
Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation);
//label.RenderTransformOrigin = new Point(0.5, 0.5);
label.RenderTransform = labelRotation;
Labels.Add(label);
Line tickLine = new Line();
double labelPadding = 0;
Binding styleBinding = new Binding();
styleBinding.Path = new PropertyPath("MajorLineStyle");
styleBinding.Source = this;
tickLine.SetBinding(Line.StyleProperty, styleBinding);
tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth));
tickLine.X1 = xAxisWidthPosition - (tickLine.DesiredSize.Width / 2);
tickLine.X2 = xAxisWidthPosition - (tickLine.DesiredSize.Width / 2);
switch (this.MajorTicksPosition)
{
case TickPosition.Inside:
tickLine.Y1 = 0;
Binding tickSizeInsideBinding = new Binding();
tickSizeInsideBinding.Path = new PropertyPath("MajorLineSize");
tickSizeInsideBinding.Source = this;
tickSizeInsideBinding.Converter = new NegativeConverter();
tickLine.SetBinding(Line.Y2Property, tickSizeInsideBinding);
if (this.ShowMajorTicks)
{
labelPadding = 0;
desiredHeight = 0;
}
break;
case TickPosition.Cross:
Binding tickSizeNegativeCrossBinding = new Binding();
tickSizeNegativeCrossBinding.Path = new PropertyPath("MajorLineSize");
tickSizeNegativeCrossBinding.Source = this;
tickSizeNegativeCrossBinding.Converter = new NegativeHalfConverter();
tickLine.SetBinding(Line.Y1Property, tickSizeNegativeCrossBinding);
Binding tickSizeCrossBinding = new Binding();
tickSizeCrossBinding.Path = new PropertyPath("MajorLineSize");
tickSizeCrossBinding.Source = this;
tickSizeCrossBinding.Converter = new HalfValueConverter();
tickLine.SetBinding(Line.Y2Property, tickSizeCrossBinding);
if (this.ShowMajorTicks)
{
labelPadding = tickLine.Y2;
desiredHeight = MajorLineSize / 2;
}
break;
case TickPosition.Outside:
tickLine.Y1 = 0;
Binding tickSizeBinding = new Binding();
tickSizeBinding.Path = new PropertyPath("MajorLineSize");
tickSizeBinding.Source = this;
tickLine.SetBinding(Line.Y2Property, tickSizeBinding);
if (this.ShowMajorTicks)
{
labelPadding = tickLine.Y2;
desiredHeight = MajorLineSize;
//.........这里部分代码省略.........