本文整理汇总了C#中System.Windows.Controls.Border.Arrange方法的典型用法代码示例。如果您正苦于以下问题:C# Border.Arrange方法的具体用法?C# Border.Arrange怎么用?C# Border.Arrange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Border
的用法示例。
在下文中一共展示了Border.Arrange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderFrame
protected override BitmapSource RenderFrame(DataRect dataRect, Rect output)
{
Grid grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
TextBlock lt = new TextBlock
{
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Left,
Text = String.Format("({0},{1})", dataRect.XMin, dataRect.YMax)
};
grid.Children.Add(lt);
Grid.SetRow(lt, 0);
TextBlock rb = new TextBlock
{
VerticalAlignment = VerticalAlignment.Bottom,
HorizontalAlignment = HorizontalAlignment.Right,
Text = String.Format("({0},{1})", dataRect.XMax, dataRect.YMin)
};
grid.Children.Add(rb);
Grid.SetRow(rb, 1);
Border border = new Border();
border.BorderThickness = new Thickness(3);
border.BorderBrush = Brushes.Blue;
border.Child = grid;
RenderTargetBitmap rtb = new RenderTargetBitmap((int)output.Width, (int)output.Height, 96, 96, PixelFormats.Default);
border.Measure(new Size(output.Width, output.Height));
border.Arrange(output);
rtb.Render(border);
Thread.Sleep(1000);
return rtb;
}
示例2: BorderHitTestTest
public void BorderHitTestTest()
{
Border border = new Border
{
Width = 200,
Height = 100,
BorderThickness = new Thickness(10, 20, 30, 40),
IsRootElement = true,
};
border.Measure(Size.Infinity);
border.Arrange(new Rect(border.DesiredSize));
BackgroundHitTestTest(border, null);
BorderHitTestTest(border, null);
border.Background = Brushes.Transparent;
border.BorderBrush = null;
BackgroundHitTestTest(border, border);
BorderHitTestTest(border, border);
border.Background = null;
border.BorderBrush = Brushes.Transparent;
BackgroundHitTestTest(border, null);
BorderHitTestTest(border, border);
border.Background = Brushes.Transparent;
border.BorderBrush = Brushes.Transparent;
BackgroundHitTestTest(border, border);
BorderHitTestTest(border, border);
}
示例3: GetPage
public override DocumentPage GetPage(int pageNumber)
{
var page = _pages[pageNumber];
var container = new Border();
container.Padding = _margin;
container.Child = page;
container.Measure(PageSize);
container.Arrange(new Rect(PageSize));
return new DocumentPage(container);
}
示例4: GetThumbnailImage
public static BitmapSource GetThumbnailImage(this BitmapSource source, double percent, double dpiX, double dpiY)
{
double width = source.PixelWidth, height = source.PixelHeight;
Algorithm.Math.ToPercentSize(percent, ref width, ref height);
RenderTargetBitmap bmp = new RenderTargetBitmap((int)width, (int)height,
dpiX, dpiY, PixelFormats.Pbgra32);
Border image = new Border();
image.RenderSize = new Size(width, height);
image.Background = new ImageBrush(source);
image.Measure(new Size(width, height));
image.Arrange(new Rect(new Size(width, height)));
bmp.Render(image);
return BitmapFrame.Create(bmp);
}
示例5: MouseDeviceButtonTest
public void MouseDeviceButtonTest()
{
Border element = new Border { Background = Brushes.Transparent, Width = 100, Height = 100, IsRootElement = true };
element.Measure(Size.Infinity);
element.Arrange(new Rect(element.DesiredSize));
int eventIndex = 0;
int previewMouseDownIndex = 0;
int previewMouseUpIndex = 0;
int mouseDownIndex = 0;
int mouseUpIndex = 0;
element.PreviewMouseDown += (sender, e) => previewMouseDownIndex = ++eventIndex;
element.PreviewMouseUp += (sender, e) => previewMouseUpIndex = ++eventIndex;
element.MouseDown += (sender, e) => mouseDownIndex = ++eventIndex;
element.MouseUp += (sender, e) => mouseUpIndex = ++eventIndex;
TestPresentationSource presentationSource = new TestPresentationSource();
presentationSource.RootElement = element;
MouseDevice mouseDevice = new MouseDevice(presentationSource);
mouseDevice.Activate();
mouseDevice.ProcessRawEvent(new RawMouseButtonEventArgs(MouseButton.Left, MouseButtonState.Pressed, new Point(10, 10), 0));
Assert.AreEqual(MouseButtonState.Pressed, mouseDevice.GetButtonState(MouseButton.Left));
Assert.AreEqual(1, previewMouseDownIndex);
Assert.AreEqual(2, mouseDownIndex);
mouseDevice.ProcessRawEvent(new RawMouseButtonEventArgs(MouseButton.Left, MouseButtonState.Released, new Point(10, 10), 0));
Assert.AreEqual(MouseButtonState.Released, mouseDevice.GetButtonState(MouseButton.Left));
Assert.AreEqual(3, previewMouseUpIndex);
Assert.AreEqual(4, mouseUpIndex);
mouseDevice.ProcessRawEvent(new RawMouseButtonEventArgs(MouseButton.Left, MouseButtonState.Pressed, new Point(10, 10), 0));
Assert.AreEqual(MouseButtonState.Pressed, mouseDevice.GetButtonState(MouseButton.Left));
Assert.AreEqual(5, previewMouseDownIndex);
Assert.AreEqual(6, mouseDownIndex);
mouseDevice.Deactivate();
Assert.AreEqual(MouseButtonState.Released, mouseDevice.GetButtonState(MouseButton.Left));
Assert.AreEqual(7, previewMouseUpIndex);
Assert.AreEqual(8, mouseUpIndex);
}
示例6: MeasureRectangleBorderTest1
public void MeasureRectangleBorderTest1 ()
{
// See 1_1 1_2 for demonstation of this as a measure invalidation bug.
Border b = new Border ();
Path p = new Path ();
p.Fill = new SolidColorBrush (Colors.Black);
RectangleGeometry r = new RectangleGeometry ();
r.Rect = new Rect (10, 10, 20, 20);
p.Data = r;
b.Child = p;
b.Measure (new Size (50, 50));
b.Arrange (new Rect (0, 0, 50, 50));
Assert.AreEqual (new Size (0,0), b.DesiredSize, "b desired");
Assert.AreEqual (new Size (50,50), b.RenderSize, "b RenderSize");
Assert.AreEqual (new Size (0,0), p.DesiredSize, "p DesiredSize");
Assert.AreEqual (new Size (50,50), p.RenderSize, "p RenderSize");
}
示例7: MeasureRectangleBorderTest1_1
public void MeasureRectangleBorderTest1_1 ()
{
// This is the same as the above test but has
Border b = new Border ();
Path p = new Path ();
b.Child = p;
p.Fill = new SolidColorBrush (Colors.Black);
RectangleGeometry r = new RectangleGeometry ();
r.Rect = new Rect (10, 10, 20, 20);
p.Data = r;
b.Measure (new Size (50, 50));
b.Arrange (new Rect (0, 0, 50, 50));
Assert.AreEqual (new Size (30,30), b.DesiredSize, "b desired");
Assert.AreEqual (new Size (30,30), p.DesiredSize, "p desired");
Assert.AreEqual (new Size (50,50), b.RenderSize, "b RenderSize");
Assert.AreEqual (new Size (50,50), p.RenderSize, "p RenderSize");
}
示例8: BorderRenderTest
public void BorderRenderTest()
{
Brush backgroundBrush = new LinearGradientBrush(30, Colors.Blue, Colors.Green);
Brush borderBrush = new LinearGradientBrush(-30, Colors.Red, Colors.Blue);
Thickness borderThickness = new Thickness(10, 20, 30, 40);
Border border = new Border
{
Child = new FrameworkElement { Width = 200, Height = 100 },
Background = backgroundBrush,
BorderBrush = borderBrush,
BorderThickness = borderThickness,
};
border.Measure(Size.Infinity);
border.Arrange(new Rect(border.DesiredSize));
IRenderElementFactory factory = TestRenderElementFactory.Default;
border.GetRenderElement(factory);
Assert.AreEqual(new Rect(240, 160), border.GetRenderElement(factory).Bounds);
Assert.AreEqual(2, border.GetRenderElement(factory).Children.Count());
IBorderRenderElement borderRenderElement = border.GetRenderElement(factory).Children.ElementAt(0) as IBorderRenderElement;
Assert.IsNotNull(borderRenderElement);
Assert.AreEqual(backgroundBrush, borderRenderElement.Background);
Assert.AreEqual(borderBrush, borderRenderElement.BorderBrush);
Assert.AreEqual(borderThickness, borderRenderElement.BorderThickness);
Assert.AreEqual(new Rect(240, 160), borderRenderElement.Bounds);
IVisualRenderElement visualRenderElement = border.GetRenderElement(factory).Children.ElementAt(1) as IVisualRenderElement;
Assert.IsNotNull(visualRenderElement);
Assert.AreEqual(new Rect(10, 20, 200, 100), visualRenderElement.Bounds);
border.Child = null;
Assert.AreEqual(1, border.GetRenderElement(factory).Children.Count());
}
示例9: LayoutSlotTest4InTree
public void LayoutSlotTest4InTree ()
{
Border b = new Border ();
var stack = new StackPanel ();
var panel = new Grid ();
panel.Children.Add (b);
panel.Background = new SolidColorBrush (Colors.Green);
stack.Children.Add (CreateSlotItem ());
stack.Children.Add (CreateSlotItem ());
stack.Children.Add (CreateSlotItem ());
stack.HorizontalAlignment = HorizontalAlignment.Right;
b.Width = 50;
b.Child = stack;
b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
Assert.AreEqual (new Size (0,0), new Size (stack.ActualWidth, stack.ActualHeight), "stack actual");
b.Arrange (new Rect (0,0,b.DesiredSize.Width,b.DesiredSize.Height));
Assert.AreEqual (new Rect (0,0,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]).ToString (), "slot0");
Assert.AreEqual (new Rect (0,33,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]).ToString (), "slot1");
Assert.AreEqual (new Rect (0,66,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]).ToString (), "slot2");
Assert.AreEqual (new Rect (0,0,50,99).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack).ToString ());
Assert.AreEqual (new Rect (0,0,50,99).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)b).ToString ());
Assert.AreEqual (new Size (50,99),b.DesiredSize);
Assert.AreEqual (new Size (25,99),stack.DesiredSize);
Assert.AreEqual (new Size (25,99), new Size (stack.ActualWidth, stack.ActualHeight), "stack actual");
TestPanel.Children.Add (panel);
Assert.AreEqual (new Size (0,0),b.DesiredSize);
Assert.AreEqual (new Size (0,0),stack.DesiredSize);
b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
Assert.AreEqual (new Size (0,0), new Size (stack.ActualWidth, stack.ActualHeight), "stack actual");
b.Arrange (new Rect (0,0,b.DesiredSize.Width,b.DesiredSize.Height));
Assert.AreEqual (new Rect (0,0,0,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]).ToString (), "slot0 in tree");
Assert.AreEqual (new Rect (0,0,0,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]).ToString (), "slot1 in tree");
Assert.AreEqual (new Rect (0,0,0,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]).ToString (), "slot2 in tree");
Assert.AreEqual (new Rect (0,0,0,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack).ToString ());
Assert.AreEqual (new Rect (0,0,0,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)b).ToString ());
Assert.AreEqual (new Size (50,99),b.DesiredSize);
Assert.AreEqual (new Size (25,99),stack.DesiredSize);
TestPanel.Children.Remove (panel);
CreateAsyncTest (panel, () => {
Assert.AreEqual (new Rect (0,0,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]).ToString (), "slot0");
Assert.AreEqual (new Rect (0,33,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]).ToString (), "slot1");
Assert.AreEqual (new Rect (0,66,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]).ToString (), "slot2");
Assert.AreEqual (new Rect (0,0,50,TestPanel.ActualHeight).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack).ToString (), "slot3");
Assert.AreEqual(new Rect(0, 0, TestPanel.ActualWidth, TestPanel.ActualHeight).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)b).ToString(), "slot4");
Assert.AreEqual (new Size (50,99),b.DesiredSize, "b desired async");
Assert.AreEqual (new Size (25,99),stack.DesiredSize, "stack desired async");
});
}
示例10: ArrangeTooLongLineTest
public void ArrangeTooLongLineTest ()
{
Border b = new Border ();
TextBlock tb = new TextBlock ();
tb.Text = "Hello and don't you forget Who I am";
b.Child = tb;
b.Width = 44;
Assert.IsTrue (tb.ActualWidth > 192.8 && tb.ActualWidth < 202.4, "1. textblock.ActualWidth is " + tb.ActualWidth.ToString ());
Assert.AreEqual (1, GetLineCount (tb.ActualHeight), "1. line count based on textblock.ActualHeight");
//Assert.IsTrue (tb.ActualWidth < 202.4 && tb.ActualWidth > 202.3, "1. tb.ActualWidth is " + tb.ActualWidth.ToString ());
//Assert.AreEqual (16, tb.ActualHeight, "1. tb.ActualHeight");
b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
Assert.IsTrue (tb.ActualWidth > 192.8 && tb.ActualWidth < 202.4, "2. textblock.ActualWidth is " + tb.ActualWidth.ToString ());
Assert.AreEqual (1, GetLineCount (tb.ActualHeight), "2. line count based on textblock.ActualHeight");
Assert.AreEqual (1, GetLineCount (tb.DesiredSize.Height), "2. line count based on textblock.DesiredSize");
Assert.AreEqual (1, GetLineCount (b.DesiredSize.Height), "2. line count based on border.DesiredSize");
//Assert.AreEqual (new Size (44,16), tb.DesiredSize, "2. tb.DesiredSize");
//Assert.AreEqual (new Size (44,16), b.DesiredSize, "2. b.DesiredSize");
//Assert.IsTrue (tb.ActualWidth < 202.4 && tb.ActualWidth > 202.3, "2. tb.ActualWidth is " + tb.ActualWidth.ToString ());
//Assert.AreEqual (16, tb.ActualHeight, "2. tb.ActualHeight");
b.Arrange (new Rect (0,0, b.DesiredSize.Width, b.DesiredSize.Height));
Assert.IsTrue (tb.ActualWidth > 192.8 && tb.ActualWidth < 202.4, "3. tb.ActualWidth is " + tb.ActualWidth.ToString ());
Assert.AreEqual (1, GetLineCount (tb.ActualHeight), "3. line count based on textblock.ActualHeight");
Assert.AreEqual (1, GetLineCount (tb.DesiredSize.Height), "3. line count based on textblock.DesiredSize");
Assert.AreEqual (1, GetLineCount (b.ActualHeight), "3. line count based on border.ActualHeight");
Assert.AreEqual (1, GetLineCount (b.DesiredSize.Height), "3. line count based on border.DesiredSize");
//Assert.AreEqual (new Size (44,16), tb.DesiredSize, "3. tb.DesiredSize");
//Assert.AreEqual (new Size (44,16), b.DesiredSize, "3. b.DesiredSize");
//Assert.IsTrue (tb.ActualWidth > 202.3 && tb.ActualWidth < 202.4,"3. tb.ActualWidth is " + tb.ActualWidth.ToString ());
//Assert.AreEqual (16, tb.ActualHeight, "3. tb.ActualHeight");
//Assert.AreEqual (new Size (44,16), new Size (b.ActualWidth, b.ActualHeight), "3. b.Actual*");
}
示例11: LayoutSlotTest2
public void LayoutSlotTest2 ()
{
Border b = new Border ();
var stack = new StackPanel ();
stack.Children.Add (CreateSlotItem ());
stack.Children.Add (CreateSlotItem ());
stack.Children.Add (CreateSlotItem ());
b.Width = 50;
b.Height = 300;
b.Child = stack;
b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
b.Arrange (new Rect (0,0,b.DesiredSize.Width,b.DesiredSize.Height));
Assert.AreEqual (new Rect (0,0,50,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]));
Assert.AreEqual (new Rect (0,33,50,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]));
Assert.AreEqual (new Rect (0,66,50,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]));
Assert.AreEqual (new Size (50,300),b.DesiredSize);
Assert.AreEqual (new Size (50,300),b.RenderSize);
}
示例12: UpdateShadow
//.........这里部分代码省略.........
container.Children.Add(cylinder);
}
}
}
}
#endregion
}
// Get bounding box
Rect3D boundingBox = VisualTreeHelper.GetDescendantBounds(container);
if (boundingBox.IsEmpty)
{
shadowRefreshStarted = false;
return;
}
#region Render Shadow
const double blurSize = 25;
const int renderTargetWidth = 200;
int renderTargetHeight = (int)(200.0 * (boundingBox.SizeX / boundingBox.SizeY));
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(renderTargetWidth, renderTargetHeight, 96, 96, PixelFormats.Pbgra32);
Viewport3D shadowViewport3D = new Viewport3D();
Border border = new Border();
border.Padding = new Thickness(blurSize);
border.Child = shadowViewport3D;
// Change size of the visualizer
border.Width = renderTargetBitmap.PixelWidth;
border.Height = renderTargetBitmap.PixelHeight;
border.Measure(new Size(renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight));
border.Arrange(new Rect(0, 0, renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight));
shadowViewport3D.Children.Add(container);
// Create camera
OrthographicCamera orthographicCamera = new OrthographicCamera();
#region Accomodate camera to fit content
orthographicCamera.Position = new Point3D(boundingBox.Location.X + boundingBox.SizeX / 2.0,
boundingBox.Location.Y,
boundingBox.Location.Z + boundingBox.SizeZ / 2.0);
orthographicCamera.LookDirection = new Vector3D(0, 1, 0);
orthographicCamera.UpDirection = new Vector3D(-1, 0, 0);
orthographicCamera.Width = boundingBox.SizeZ;
#endregion
orthographicCamera.NearPlaneDistance = 0;
// Set the camera & correct lights
shadowViewport3D.Camera = orthographicCamera;
BlurEffect blurEffect = new BlurEffect();
blurEffect.Radius = blurSize;
border.Effect = blurEffect;
renderTargetBitmap.Render(border);
renderTargetBitmap.Freeze();
#endregion
示例13: drawHeaderForBox
// Assumes that the bitmapcontext is active
private void drawHeaderForBox(WriteableBitmap bitmap, int x, int y, int width, String text)
{
const int BOX_HEIGHT = 40;
const int BOX_WIDTH = 120;
TranslateTransform transform = new TranslateTransform();
transform.X = x + (width - BOX_WIDTH) / 2;
transform.Y = y;
Border border = new Border();
border.Height = BOX_HEIGHT;
border.Width = BOX_WIDTH;
border.Background = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0));
TextBlock textBlock = new TextBlock();
textBlock.FontSize = 36;
textBlock.TextAlignment = TextAlignment.Center;
textBlock.Foreground = new SolidColorBrush(Colors.White);
textBlock.Text = text;
border.Child = textBlock;
border.Arrange(new Rect(0.0, 0.0, border.Width, border.Height));
border.UpdateLayout();
bitmap.Render(border, transform);
}
示例14: Arrange_Rounding
public void Arrange_Rounding()
{
Border b = new Border ();
var path = new Path ();
//var canvas = new Canvas ();
b.Child = path;
//canvas.Children.Add (b);
RectangleGeometry r = new RectangleGeometry ();
r.Rect = new Rect (10, 10, 80.1, .2);
path.Data = r;
path.Width = 20;
path.Height = 20;
path.Fill = new SolidColorBrush (Colors.Red);
b.Measure (new Size (120, 120));
Assert.IsTrue (path.UseLayoutRounding, "path rounds?");
Assert.AreEqual (new Size (20,20), path.DesiredSize, "desired");
Assert.AreEqual (new Size (0,0), path.RenderSize, "render");
Assert.AreEqual (0, path.ActualWidth);
Assert.AreEqual (0, path.ActualHeight);
b.Arrange (new Rect (0, 0, 120, 120));
Assert.AreEqual (new Size (20,20), path.DesiredSize, "desired");
Assert.AreEqual (new Size (90,20), path.RenderSize, "render");
Assert.AreEqual (90, path.ActualWidth);
Assert.AreEqual (20, path.ActualHeight);
}
示例15: MeasureRectangleBorderTest1_2
public void MeasureRectangleBorderTest1_2 ()
{
// See test 1_1 and 1 for more information
Border b = new Border ();
Path p = new Path ();
p.Fill = new SolidColorBrush (Colors.Black);
RectangleGeometry r = new RectangleGeometry ();
r.Rect = new Rect (10, 10, 20, 20);
p.Data = r;
b.Child = p;
p.InvalidateMeasure ();
b.Measure (new Size (50, 50));
b.Arrange (new Rect (0, 0, 50, 50));
Assert.AreEqual (new Size (30,30), b.DesiredSize, "b desired");
Assert.AreEqual (new Size (30,30), p.DesiredSize, "p DesiredSize");
Assert.AreEqual (new Size (50,50), b.RenderSize, "b RenderSize");
Assert.AreEqual (new Size (50,50), p.RenderSize, "p RenderSize");
}