本文整理汇总了C#中System.Windows.Controls.StackPanel.Measure方法的典型用法代码示例。如果您正苦于以下问题:C# StackPanel.Measure方法的具体用法?C# StackPanel.Measure怎么用?C# StackPanel.Measure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.StackPanel
的用法示例。
在下文中一共展示了StackPanel.Measure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArrangeTest
public void ArrangeTest ()
{
Border b1 = new Border ();
b1.Background = new SolidColorBrush (Colors.Red);
b1.Width = 50;
b1.Height = 25;
Border b2 = new Border ();
b2.Background = new SolidColorBrush (Colors.Blue);
b2.Width = 25;
b2.Height = 30;
var stack = new StackPanel ();
stack.Children.Add (b1);
stack.Children.Add (b2);
stack.Measure (new Size (Double.PositiveInfinity,Double.PositiveInfinity));
Assert.AreEqual (new Size (50,55), stack.DesiredSize, "stack desired");
Assert.AreEqual (new Size (0,0), new Size (stack.ActualWidth, stack.ActualHeight), "stack actual");
stack.Arrange (new Rect (10, 10, stack.DesiredSize.Width, stack.DesiredSize.Height));
Assert.AreEqual (new Size (50,55), stack.DesiredSize, "stack desired1");
Assert.AreEqual (new Size (50,55), stack.RenderSize, "stack render1");
Assert.AreEqual (new Rect (10,10,50,55), LayoutInformation.GetLayoutSlot (stack), "stack slot");
}
示例2: StackPanelLayoutTest
public void StackPanelLayoutTest()
{
StackPanel panel = new StackPanel();
FrameworkElement child1 = new FrameworkElement { Height = 100 };
FrameworkElement child2 = new FrameworkElement { Height = 100 };
FrameworkElement child3 = new FrameworkElement { Height = 100 };
panel.Children.Add(child1);
panel.Children.Add(child2);
panel.Children.Add(child3);
panel.Measure(new Size(1000, 1000));
Assert.AreEqual(new Size(0, 300), panel.DesiredSize);
panel.Arrange(new Rect(1000, 300));
Assert.AreEqual(new Size(1000, 300), panel.VisualSize);
Assert.AreEqual(new Size(1000, 100), child1.VisualSize);
Assert.AreEqual(new Size(1000, 100), child2.VisualSize);
Assert.AreEqual(new Size(1000, 100), child3.VisualSize);
Assert.AreEqual(new Point(0, 0), child1.VisualOffset);
Assert.AreEqual(new Point(0, 100), child2.VisualOffset);
Assert.AreEqual(new Point(0, 200), child3.VisualOffset);
}
示例3: LayoutSlotTest
public void LayoutSlotTest ()
{
var stack = new StackPanel ();
stack.Children.Add (CreateSlotItem ());
stack.Children.Add (CreateSlotItem ());
stack.Children.Add (CreateSlotItem ());
stack.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
stack.Arrange (new Rect (0,0,stack.DesiredSize.Width,stack.DesiredSize.Height));
Assert.AreEqual (new Rect (0,0,25,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]));
Assert.AreEqual (new Rect (0,33,25,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]));
Assert.AreEqual (new Rect (0,66,25,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]));
}
示例4: MouseDeviceCaptureTest
public void MouseDeviceCaptureTest()
{
Border child1 = new Border { Background = Brushes.Transparent, Width = 100, Height = 100 };
Border child2 = new Border { Background = Brushes.Transparent, Width = 100, Height = 100 };
Border child3 = new Border { Background = Brushes.Transparent, Width = 100, Height = 100 };
StackPanel panel = new StackPanel { IsRootElement = true };
panel.Children.Add(child1);
panel.Children.Add(child2);
MouseEventArgs lastArgs = null;
panel.MouseMove += (sender, e) => lastArgs = e;
TestPresentationSource presentationSource = new TestPresentationSource();
presentationSource.RootElement = panel;
panel.Measure(Size.Infinity);
panel.Arrange(new Rect(panel.DesiredSize));
MouseDevice mouseDevice = new MouseDevice(presentationSource);
mouseDevice.Activate();
mouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 50), 0));
Assert.AreEqual(child1, lastArgs.Source);
Assert.AreEqual(child1, mouseDevice.HitTarget);
Assert.AreEqual(null, mouseDevice.CaptureTarget);
Assert.AreEqual(child1, mouseDevice.Target);
mouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 150), 0));
Assert.AreEqual(child2, lastArgs.Source);
Assert.AreEqual(child2, mouseDevice.HitTarget);
Assert.AreEqual(null, mouseDevice.CaptureTarget);
Assert.AreEqual(child2, mouseDevice.Target);
mouseDevice.Capture(child2);
mouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 50), 0));
Assert.AreEqual(child2, lastArgs.Source);
Assert.AreEqual(child1, mouseDevice.HitTarget);
Assert.AreEqual(child2, mouseDevice.CaptureTarget);
Assert.AreEqual(child2, mouseDevice.Target);
mouseDevice.ReleaseCapture();
mouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 50), 0));
Assert.AreEqual(child1, lastArgs.Source);
Assert.AreEqual(child1, mouseDevice.HitTarget);
Assert.AreEqual(null, mouseDevice.CaptureTarget);
Assert.AreEqual(child1, mouseDevice.Target);
}
示例5: MeasureTest
public void MeasureTest ()
{
Border b1 = new Border ();
b1.Background = new SolidColorBrush (Colors.Red);
b1.Width = 50;
b1.Height = 25;
Border b2 = new Border ();
b2.Background = new SolidColorBrush (Colors.Blue);
b2.Width = 25;
b2.Height = 30;
var stack = new StackPanel ();
stack.Children.Add (b1);
stack.Children.Add (b2);
stack.Measure (new Size (Double.PositiveInfinity,Double.PositiveInfinity));
Assert.AreEqual (new Size (50,55), stack.DesiredSize, "stack desired");
}
示例6: Print_Click
private void Print_Click(object sender, RoutedEventArgs e)
{
PrintDialog printDlg = new PrintDialog();
if (printDlg.ShowDialog() == true)
{
printDlg.PrintTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.NorthAmerica4x6);
//printDlg.PrintQueue.DefaultPrintTicket.PageOrientation = PageOrientation.Landscape;
printDlg.PrintTicket.PageOrientation = PageOrientation.Landscape;
Console.WriteLine("wwwwwwwwwwwwww->" + printDlg.PrintableAreaWidth);
Console.WriteLine("hhhhhhhhhhhhhhh->" + printDlg.PrintableAreaHeight);
Console.WriteLine("W-> "+printDlg.PrintTicket.PageMediaSize.Width);
Console.WriteLine("H-> "+printDlg.PrintTicket.PageMediaSize.Height);
//printDlg.PrintQueue.DefaultPrintTicket.PageOrientation = PageOrientation.Portrait;
/*
XpsDocumentWriter docWriter = PrintQueue.CreateXpsDocumentWriter(printDlg.PrintQueue);
PrintTicket ticket = new PrintTicket();
if (printDlg.PrintTicket.PageOrientation == PageOrientation.Landscape)
{
ticket.PageMediaSize =
new PageMediaSize(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight);
}
docWriter.Write(visual, ticket);
*/
Size size = new Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight);
StackPanel stackPanel = new StackPanel { Orientation = Orientation.Vertical, RenderSize = size };
//TextBlock title = new TextBlock { Text = @"Form", FontSize = 20 };
//stackPanel.Children.Add(title);
Image image = new Image { Source = this.theImage.Source, Stretch = Stretch.Uniform };
image.RenderTransform = new ScaleTransform(1, 1);
stackPanel.Children.Add(image);
stackPanel.Measure(size);
stackPanel.Arrange(new Rect(new Point(0, 0), stackPanel.DesiredSize));
printDlg.PrintVisual(stackPanel, @"Form image");
//printDlg.PrintVisual(theImage, "My First Print Job");
}
}
示例7: Print
internal void Print(System.Windows.Controls.Image ImageCtrl)
{
PrintDialog printDlg = new PrintDialog();
if (printDlg.ShowDialog() == true)
{
printDlg.PrintTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.NorthAmerica4x6);
printDlg.PrintTicket.PageOrientation = PageOrientation.Landscape;
System.Windows.Size size = new System.Windows.Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight);
StackPanel stackPanel = new StackPanel { Orientation = Orientation.Vertical, RenderSize = size };
//TextBlock title = new TextBlock { Text = @"Form", FontSize = 20 };
//stackPanel.Children.Add(title);
TransformGroup transformGroup = new TransformGroup();
ScaleTransform scaleTransform = new ScaleTransform(1,1);
transformGroup.Children.Add(scaleTransform);
Image image = new Image { Source = ImageCtrl.Source, Stretch = Stretch.Uniform };
//image.RenderTransform = new ScaleTransform(1, 1);
BitmapSource imgSrouce = ImageCtrl.Source as BitmapSource;
if (imgSrouce.PixelWidth < imgSrouce.PixelHeight)
{
image.LayoutTransform = new RotateTransform(90);
}
image.RenderTransform = transformGroup;
stackPanel.Children.Add(image);
stackPanel.Measure(size);
stackPanel.Arrange(new Rect(new Point(0, 0), stackPanel.DesiredSize));
printDlg.PrintVisual(stackPanel, @"Form image");
//printDlg.PrintVisual(ImageCtrl, "My First Print Job");
}
}
示例8: HitTestBasicTest
public void HitTestBasicTest()
{
StackPanel stackPanel1 = new StackPanel { Name = "stackPanel1", Background = Brushes.Transparent, IsRootElement = true };
StackPanel stackPanel2 = new StackPanel { Name = "stackPanel2", Background = Brushes.Transparent, Height = 100, Orientation = Orientation.Horizontal };
Border child1 = new Border { Name = "child1", Background = Brushes.Transparent, Height = 100, Width = 100 };
Border child2 = new Border { Name = "child2", Background = Brushes.Transparent, Height = 100 };
Border child3 = new Border { Name = "child3", Background = Brushes.Transparent, Width = 100 };
Border child4 = new Border { Name = "child4", Background = Brushes.Transparent, Width = 100 };
stackPanel1.Children.Add(child1);
stackPanel1.Children.Add(stackPanel2);
stackPanel1.Children.Add(child2);
stackPanel2.Children.Add(child3);
stackPanel2.Children.Add(child4);
// [child1] ]
// [child3][child4]
// [child2 ]
stackPanel1.Measure(Size.Infinity);
stackPanel1.Arrange(new Rect(stackPanel1.DesiredSize));
Assert.AreEqual(child1, stackPanel1.HitTest(new Point(50, 50)));
Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(150, 50)));
Assert.AreEqual(child3, stackPanel1.HitTest(new Point(50, 150)));
Assert.AreEqual(child4, stackPanel1.HitTest(new Point(150, 150)));
Assert.AreEqual(child2, stackPanel1.HitTest(new Point(50, 250)));
Assert.AreEqual(child2, stackPanel1.HitTest(new Point(150, 250)));
stackPanel2.IsEnabled = false;
Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(50, 150)));
Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(150, 150)));
child2.IsHitTestVisible = false;
Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(50, 250)));
Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(150, 250)));
}
示例9: Window_Loaded
private void Window_Loaded(object sender, RoutedEventArgs e)
{
System.Windows.Size size = new System.Windows.Size(600, 400);
StackPanel stackPanel = new StackPanel { Orientation = Orientation.Vertical, RenderSize = size };
System.Windows.Controls.Image ImageCtrl = new System.Windows.Controls.Image();
BitmapImage bitImg = new BitmapImage(new Uri("C:\\temp\\32367-78aNJdO.jpg"));
ImageCtrl.Source = bitImg;
TransformGroup transformGroup = new TransformGroup();
ScaleTransform scaleTransform = new ScaleTransform(1, 1);
transformGroup.Children.Add(scaleTransform);
System.Windows.Controls.Image image = new System.Windows.Controls.Image { Source = ImageCtrl.Source, Stretch = Stretch.Uniform };
//image.RenderTransform = new ScaleTransform(1, 1);
BitmapSource imgSrouce = ImageCtrl.Source as BitmapSource;
if (imgSrouce.PixelWidth < imgSrouce.PixelHeight)
{
/*
double argle = 90 * 180 / 3.142;
RotateTransform rotateTransform = new RotateTransform();
rotateTransform.Angle = argle;
transformGroup.Children.Add(rotateTransform);
* */
image.LayoutTransform = new RotateTransform(90);
}
image.RenderTransform = transformGroup;
stackPanel.Children.Add(image);
stackPanel.Measure(size);
stackPanel.Arrange(new Rect(new System.Windows.Point(0, 0), stackPanel.DesiredSize));
this.AddChild(stackPanel);
}
示例10: LayoutSlotTest_Flow
public void LayoutSlotTest_Flow ()
{
var stack = new StackPanel ();
var border = new Border () { Width = 100, Height = 200 };
border.Child = stack;
stack.FlowDirection = FlowDirection.RightToLeft;
stack.Orientation = Orientation.Horizontal;
var child0 = CreateSlotItem ();
var child1 = CreateSlotItem ();
child1.FlowDirection = FlowDirection.LeftToRight;
stack.Children.Add (child0);
stack.Children.Add (child1);
stack.Children.Add (CreateSlotItem ());
stack.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
stack.Arrange (new Rect (0,0,stack.DesiredSize.Width,stack.DesiredSize.Height));
Assert.AreEqual (new Rect (0,0,25,33), LayoutInformation.GetLayoutSlot (child0));
Assert.AreEqual (new Rect (25,0,25,33), LayoutInformation.GetLayoutSlot (child1));
Assert.AreEqual (new Rect (50,0,25,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]));
CreateAsyncTest (border, () => {
MatrixTransform xform0 = child0.TransformToVisual (border) as MatrixTransform;
Assert.AreEqual ("-1,0,0,1,100,84", xform0.Matrix.ToString(), "transform0 string");
MatrixTransform xform1 = child1.TransformToVisual (border) as MatrixTransform;
Assert.AreEqual ("1,0,0,1,50,84", xform1.Matrix.ToString(), "transform1 string");
MatrixTransform xform0_st = child0.TransformToVisual (stack) as MatrixTransform;
Assert.AreEqual ("1,0,0,1,0,84", xform0_st.Matrix.ToString(), "transform0_st string");
MatrixTransform xform1_st = child1.TransformToVisual (stack) as MatrixTransform;
Assert.AreEqual ("-1,0,0,1,50,84", xform1_st.Matrix.ToString(), "transform1_st string");
});
}
示例11: BuildOverlay2D
private void BuildOverlay2D(SOMNode node, ISOMInput[] images, bool showCount, bool showNodeHash, bool showImageHash, bool showSpread, bool showPerImageDistance)
{
const int IMAGESIZE = 80;
const int NODEHASHSIZE = 100;
const double SMALLFONT1 = 17;
const double LARGEFONT1 = 21;
const double SMALLFONT2 = 15;
const double LARGEFONT2 = 18;
const double SMALLFONT3 = 12;
const double LARGEFONT3 = 14;
const double SMALLLINE1 = .8;
const double LARGELINE1 = 1;
const double SMALLLINE2 = .5;
const double LARGELINE2 = .85;
const double SMALLLINE3 = .3;
const double LARGELINE3 = .7;
Canvas canvas = new Canvas();
List<Rect> rectangles = new List<Rect>();
#region cursor rectangle
var cursorRect = SelfOrganizingMapsWPF.GetMouseCursorRect(0);
rectangles.Add(cursorRect.Item1);
// This is just for debugging
//Rectangle cursorVisual = new Rectangle()
//{
// Width = cursorRect.Item1.Width,
// Height = cursorRect.Item1.Height,
// Fill = new SolidColorBrush(UtilityWPF.GetRandomColor(64, 192, 255)),
//};
//Canvas.SetLeft(cursorVisual, cursorRect.Item1.Left);
//Canvas.SetTop(cursorVisual, cursorRect.Item1.Top);
//canvas.Children.Add(cursorVisual);
#endregion
#region count text
if (showCount)
{
StackPanel textPanel = new StackPanel()
{
Orientation = Orientation.Horizontal,
};
// "images "
OutlinedTextBlock text = SelfOrganizingMapsWPF.GetOutlineText("images ", SMALLFONT1, SMALLLINE1);
text.Margin = new Thickness(0, 0, 4, 0);
textPanel.Children.Add(text);
// count
text = SelfOrganizingMapsWPF.GetOutlineText(images.Length.ToString("N0"), LARGEFONT1, LARGELINE1);
textPanel.Children.Add(text);
// Place on canvas
textPanel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); // aparently, the infinity is important to get an accurate desired size
Size textSize = textPanel.DesiredSize;
Rect textRect = SelfOrganizingMapsWPF.GetFreeSpot(textSize, new Point(0, 0), new Vector(0, 1), rectangles);
rectangles.Add(textRect);
Canvas.SetLeft(textPanel, textRect.Left);
Canvas.SetTop(textPanel, textRect.Top);
canvas.Children.Add(textPanel);
}
#endregion
#region spread
var nodeImages = images.Select(o => o.Weights);
var allImages = _imagesByNode.SelectMany(o => o).Select(o => o.Weights);
double nodeSpread = images.Length == 0 ? 0d : SelfOrganizingMaps.GetTotalSpread(nodeImages);
double totalSpread = SelfOrganizingMaps.GetTotalSpread(allImages);
if (showSpread && images.Length > 0)
{
double nodeStandDev = MathND.GetStandardDeviation(nodeImages);
double totalStandDev = MathND.GetStandardDeviation(allImages);
double percentSpread = nodeSpread / totalSpread;
double pecentStandDev = nodeStandDev / totalSpread;
Grid spreadPanel = new Grid()
{
Margin = new Thickness(2),
};
spreadPanel.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) });
spreadPanel.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(4) });
spreadPanel.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) });
spreadPanel.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
spreadPanel.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(2) });
//.........这里部分代码省略.........
示例12: BuildOverlay2D
private void BuildOverlay2D(SOMNode node, ISOMInput[] inputs, bool showCount = false, bool showNodeHash = false)
{
const double SMALLFONT1 = 17;
const double LARGEFONT1 = 21;
const double SMALLFONT2 = 15;
const double LARGEFONT2 = 18;
const double SMALLFONT3 = 12;
const double LARGEFONT3 = 14;
const double SMALLLINE1 = .8;
const double LARGELINE1 = 1;
const double SMALLLINE2 = .5;
const double LARGELINE2 = .85;
const double SMALLLINE3 = .3;
const double LARGELINE3 = .7;
Canvas canvas = new Canvas();
List<Rect> rectangles = new List<Rect>();
#region cursor rectangle
var cursorRect = SelfOrganizingMapsWPF.GetMouseCursorRect();
rectangles.Add(cursorRect.Item1);
// This is just for debugging
//Rectangle cursorVisual = new Rectangle()
//{
// Width = cursorRect.Item1.Width,
// Height = cursorRect.Item1.Height,
// Fill = new SolidColorBrush(UtilityWPF.GetRandomColor(64, 192, 255)),
//};
//Canvas.SetLeft(cursorVisual, cursorRect.Item1.Left);
//Canvas.SetTop(cursorVisual, cursorRect.Item1.Top);
//canvas.Children.Add(cursorVisual);
#endregion
#region count text
if (showCount && _result != null && _result.InputsByNode != null) // it's possible that they are changing things while old graphics are still showing
{
StackPanel textPanel = new StackPanel()
{
Orientation = Orientation.Horizontal,
};
// "rows "
OutlinedTextBlock text = SelfOrganizingMapsWPF.GetOutlineText("rows ", SMALLFONT1, SMALLLINE1);
text.Margin = new Thickness(0, 0, 4, 0);
textPanel.Children.Add(text);
// percent
double percent = -1;
if (_result.InputsByNode.Length == 0)
{
if (inputs.Length == 0)
{
percent = 0;
}
else
{
percent = -1;
}
}
else
{
percent = inputs.Length.ToDouble() / _result.InputsByNode.SelectMany(o => o).Count().ToDouble();
percent *= 100d;
}
text = SelfOrganizingMapsWPF.GetOutlineText(percent.ToStringSignificantDigits(2) + "%", LARGEFONT1, LARGELINE1);
textPanel.Children.Add(text);
// Place on canvas
textPanel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); // aparently, the infinity is important to get an accurate desired size
Size textSize = textPanel.DesiredSize;
Rect textRect = SelfOrganizingMapsWPF.GetFreeSpot(textSize, new Point(0, 0), new Vector(0, -1), rectangles);
rectangles.Add(textRect);
Canvas.SetLeft(textPanel, textRect.Left);
Canvas.SetTop(textPanel, textRect.Top);
canvas.Children.Add(textPanel);
}
#endregion
double[] nodeCenter = inputs.Length == 0 ? node.Weights : MathND.GetCenter(inputs.Select(o => o.Weights));
#region node hash
if (showNodeHash)
{
var nodeCtrl = GetVectorVisual(node.Weights);
// Place on canvas
Rect nodeRect = SelfOrganizingMapsWPF.GetFreeSpot(new Size(nodeCtrl.Item2.X, nodeCtrl.Item2.Y), new Point(0, 0), new Vector(0, -1), rectangles);
rectangles.Add(nodeRect);
//.........这里部分代码省略.........
示例13: Print_Click
private void Print_Click(object sender, RoutedEventArgs e)
{
PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog() == true)
{
StackPanel panel = new StackPanel();
panel.Margin = new Thickness(15);
panel.Children.Add((Canvas)XamlReader.Parse(XamlWriter.Save(this.DrawingHost.DrawingControl)));
TextBlock myBlock = new TextBlock();
myBlock.Text = "Drawing";
myBlock.TextAlignment = TextAlignment.Center;
panel.Children.Add(myBlock);
panel.Measure(new Size(dialog.PrintableAreaWidth,
dialog.PrintableAreaHeight));
panel.Arrange(new Rect(new System.Windows.Point(0, 0), panel.DesiredSize));
dialog.PrintTicket.PageOrientation = PageOrientation.Landscape;
dialog.PrintVisual(panel, "Drawing");
}
}
示例14: AssertValid
//.........这里部分代码省略.........
WpfGraphicsUtil.GetScreenDpi(m_oNodeXLControl).Width;
// The NodeXLControl can't be a child of two logical trees, so
// disconnect it from its parent after saving the current vertex
// locations.
m_oLayoutSaver = new LayoutSaver(m_oNodeXLControl.Graph);
Debug.Assert(m_oNodeXLControl.Parent is Panel);
m_oParentPanel = (Panel)m_oNodeXLControl.Parent;
UIElementCollection oParentChildren = m_oParentPanel.Children;
m_iChildIndex = oParentChildren.IndexOf(m_oNodeXLControl);
oParentChildren.Remove(m_oNodeXLControl);
m_oGraphImageScaler = new GraphImageScaler(m_oNodeXLControl);
m_oGraphImageCenterer = new NodeXLControl.GraphImageCenterer(
m_oNodeXLControl);
// The header and footer are rendered as Label controls. The legend is
// rendered as a set of Image controls.
Label oHeaderLabel, oFooterLabel;
IEnumerable<Image> oLegendImages;
Double dHeaderHeight, dTotalLegendHeight, dFooterHeight;
CreateHeaderOrFooterLabel(headerText, compositeWidth, headerFooterFont,
out oHeaderLabel, out dHeaderHeight);
CreateLegendImages(legendControls, compositeWidth, out oLegendImages,
out dTotalLegendHeight);
CreateHeaderOrFooterLabel(footerText, compositeWidth, headerFooterFont,
out oFooterLabel, out dFooterHeight);
m_oNodeXLControl.Width = compositeWidth;
m_oNodeXLControl.Height = Math.Max(10,
compositeHeight - dHeaderHeight - dTotalLegendHeight
- dFooterHeight);
// Adjust the control's graph scale so that the graph's vertices and
// edges will be the same relative size in the composite that they are
// in the control.
m_oGraphImageScaler.SetGraphScale(
(Int32)WpfGraphicsUtil.WpfToPx(compositeWidth, dScreenDpi),
(Int32)WpfGraphicsUtil.WpfToPx(m_oNodeXLControl.Height, dScreenDpi),
dScreenDpi);
// Adjust the NodeXLControl's translate transforms so that the
// composite will be centered on the same point on the graph that the
// NodeXLControl is centered on.
m_oGraphImageCenterer.CenterGraphImage( new Size(compositeWidth,
m_oNodeXLControl.Height) );
StackPanel oStackPanel = new StackPanel();
UIElementCollection oStackPanelChildren = oStackPanel.Children;
// To avoid a solid black line at the bottom of the header or the top
// of the footer, which is caused by rounding errors, make the
// StackPanel background color the same as the header and footer.
oStackPanel.Background = HeaderFooterBackgroundBrush;
if (oHeaderLabel != null)
{
oStackPanelChildren.Add(oHeaderLabel);
}
// Wrap the NodeXLControl in a Grid to clip it.
m_oGrid = new Grid();
m_oGrid.Width = m_oNodeXLControl.Width;
m_oGrid.Height = m_oNodeXLControl.Height;
m_oGrid.ClipToBounds = true;
m_oGrid.Children.Add(m_oNodeXLControl);
oStackPanelChildren.Add(m_oGrid);
foreach (Image oLegendImage in oLegendImages)
{
oStackPanelChildren.Add(oLegendImage);
}
if (oFooterLabel != null)
{
oStackPanelChildren.Add(oFooterLabel);
}
Size oCompositeSize = new Size(compositeWidth, compositeHeight);
Rect oCompositeRectangle = new Rect(new Point(), oCompositeSize);
oStackPanel.Measure(oCompositeSize);
oStackPanel.Arrange(oCompositeRectangle);
oStackPanel.UpdateLayout();
return (oStackPanel);
}
示例15: MouseDeviceQueryCursorTest
public void MouseDeviceQueryCursorTest()
{
Border child1 = new Border { Background = Brushes.Transparent, Width = 100, Height = 100 };
Border child2 = new Border { Background = Brushes.Transparent, Width = 100, Height = 100 };
StackPanel panel = new StackPanel { IsRootElement = true };
panel.Children.Add(child1);
panel.Children.Add(child2);
TestPresentationSource presentationSource = new TestPresentationSource();
presentationSource.RootElement = panel;
((TestApplicationHost)ApplicationHost.Current).PresentationSourceFactory = new TestPresentationSourceFactory(presentationSource);
panel.Measure(Size.Infinity);
panel.Arrange(new Rect(panel.DesiredSize));
child1.Cursor = Cursors.Help;
child2.Cursor = Cursors.Pen;
presentationSource.MouseDevice.Activate();
Assert.AreEqual(Cursors.Arrow, presentationSource.MouseDevice.Cursor);
presentationSource.MouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 50), 0));
Assert.AreEqual(Cursors.Help, presentationSource.MouseDevice.Cursor);
presentationSource.MouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 150), 0));
Assert.AreEqual(Cursors.Pen, presentationSource.MouseDevice.Cursor);
child2.Cursor = Cursors.Hand;
Assert.AreEqual(Cursors.Hand, presentationSource.MouseDevice.Cursor);
panel.Cursor = Cursors.Arrow;
Assert.AreEqual(Cursors.Hand, presentationSource.MouseDevice.Cursor);
panel.ForceCursor = true;
Assert.AreEqual(Cursors.Arrow, presentationSource.MouseDevice.Cursor);
((TestApplicationHost)ApplicationHost.Current).PresentationSourceFactory = null;
}