本文整理汇总了C#中System.Windows.Size类的典型用法代码示例。如果您正苦于以下问题:C# Size类的具体用法?C# Size怎么用?C# Size使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Size类属于System.Windows命名空间,在下文中一共展示了Size类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static Uri Create(string filename, string text, SolidColorBrush backgroundColor, double textSize, Size size)
{
var background = new Rectangle();
background.Width = size.Width;
background.Height = size.Height;
background.Fill = backgroundColor;
var textBlock = new TextBlock();
textBlock.Width = 500;
textBlock.Height = 500;
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Text = text;
textBlock.FontSize = textSize;
textBlock.Foreground = new SolidColorBrush(Colors.White);
textBlock.FontFamily = new FontFamily("Segoe WP");
var tileImage = "/Shared/ShellContent/" + filename;
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
var bitmap = new WriteableBitmap((int)size.Width, (int)size.Height);
bitmap.Render(background, new TranslateTransform());
bitmap.Render(textBlock, new TranslateTransform() { X = 39, Y = 88 });
var stream = store.CreateFile(tileImage);
bitmap.Invalidate();
bitmap.SaveJpeg(stream, (int)size.Width, (int)size.Height, 0, 99);
stream.Close();
}
return new Uri("ms-appdata:///local" + tileImage, UriKind.Absolute);
}
示例2: XmlRenderer
public XmlRenderer(System.Windows.Size size)
{
Size = size;
m_stream = new MemoryStream();
m_writer = new XmlTextWriter(m_stream, Encoding.UTF8);
m_writer.Formatting = Formatting.Indented;
}
示例3: PreparePrinting
public void PreparePrinting(PrintTicket printTicket, Size pageSize)
{
printTicket.PageOrientation = pageSize.Height >= pageSize.Width ? PageOrientation.Portrait : PageOrientation.Landscape;
var printExtension = _reportProvider as IReportPrintExtension;
if (printExtension != null)
printExtension.PreparePrinting(printTicket, pageSize);
}
示例4: MeasureOverride
protected override Size MeasureOverride(Size availableSize)
{
m_itemHeight = ItemRender.ItemHeight;
ScrollMax = Math.Max(0, m_itemHeight* (m_list == null? 0 : m_list.Count) - m_clipSize.Height + 2 * m_itemHeight);
ViewportSize = m_clipSize.Height;
return new Size(Width, ScrollMax );
}
示例5: MeasureOverride
protected override Size MeasureOverride(Size availableSize)
{
Size infiniteSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
double curX = 0, curY = 0, curLineHeight = 0;
foreach (UIElement child in Children)
{
child.Measure(infiniteSize);
if (curX + child.DesiredSize.Width > availableSize.Width)
{ //Wrap to next line
curY += curLineHeight;
curX = 0;
curLineHeight = 0;
}
curX += child.DesiredSize.Width;
if (child.DesiredSize.Height > curLineHeight)
curLineHeight = child.DesiredSize.Height;
}
curY += curLineHeight;
Size resultSize = new Size();
resultSize.Width = double.IsPositiveInfinity(availableSize.Width)
? curX : availableSize.Width;
resultSize.Height = double.IsPositiveInfinity(availableSize.Height)
? curY : availableSize.Height;
return resultSize;
}
示例6: MeasureOverride
/// <summary>
/// Measures the size required for all the child elements in this panel.
/// </summary>
/// <param name="constraint">The size constraint given by our parent.</param>
/// <returns>The requested size for this panel including all children</returns>
protected override Size MeasureOverride(Size constraint)
{
double col1Width = 0;
double col2Width = 0;
RowHeights.Clear();
// First, measure all the left column children
for (int i = 0; i < VisualChildrenCount; i += 2)
{
var child = Children[i];
child.Measure(constraint);
col1Width = Math.Max(child.DesiredSize.Width, col1Width);
RowHeights.Add(child.DesiredSize.Height);
}
// Then, measure all the right column children, they get whatever remains in width
var newWidth = Math.Max(0, constraint.Width - col1Width - ColumnSpacing);
Size newConstraint = new Size(newWidth, constraint.Height);
for (int i = 1; i < VisualChildrenCount; i += 2)
{
var child = Children[i];
child.Measure(newConstraint);
col2Width = Math.Max(child.DesiredSize.Width, col2Width);
RowHeights[i / 2] = Math.Max(RowHeights[i / 2], child.DesiredSize.Height);
}
Column1Width = col1Width;
return new Size(
col1Width + ColumnSpacing + col2Width,
RowHeights.Sum() + ((RowHeights.Count - 1) * RowSpacing));
}
示例7: ArrangeOverride
protected override Size ArrangeOverride (Size finalSize)
{
Tester.WriteLine ("ArrangeOverride input = " + finalSize.ToString ());
Size output = base.MeasureOverride (finalSize);
Tester.WriteLine ("ArrangeOverride output = " + output.ToString ());
return output;
}
示例8: MeasureOverride
/// <summary>
/// Calculate the actual size because it is unknown otherwise, since we
/// are using a canvas.
/// </summary>
protected override Size MeasureOverride(Size constraint)
{
Size size = new Size();
foreach (UIElement element in this.InternalChildren)
{
double left = Canvas.GetLeft(element);
double top = Canvas.GetTop(element);
left = double.IsNaN(left) ? 0 : left;
top = double.IsNaN(top) ? 0 : top;
//measure desired size for each child
element.Measure(constraint);
Size desiredSize = element.DesiredSize;
if (!double.IsNaN(desiredSize.Width) && !double.IsNaN(desiredSize.Height))
{
size.Width = Math.Max(size.Width, left + desiredSize.Width);
size.Height = Math.Max(size.Height, top + desiredSize.Height);
}
}
// add margin
size.Width += 10;
size.Height += 10;
return size;
}
示例9: PageCompositor
public PageCompositor(BookModel book, int fontSize, Size pageSize, IList<BookImage> images)
{
_book = book;
_fontSize = fontSize;
_pageSize = pageSize;
_images = images;
}
示例10: ArrangeOverride
protected override Size ArrangeOverride(Size finalSize)
{
if(ParentRow == null)
return base.ArrangeOverride(finalSize);
double totalWidth = 0d;
Children.OfType<TimespanHeaderCell>().ToList().ForEach(cell =>
{
double width = cell.DesiredSize.Width;
double x = totalWidth + ParentRow.CellBorderThickness.Left + ParentRow.CellBorderThickness.Right;
if (x + width > finalSize.Width)
{
width -= (x + width) - finalSize.Width;
}
if (width < 0)
width = 0;
cell.Arrange(new Rect(x, 0, width, finalSize.Height));
totalWidth += width;
}
);
return finalSize;
}
示例11: ArrangeOverride
protected override Size ArrangeOverride( Size finalSize ) {
foreach ( UIElement child in this.InternalChildren ) {
child.Arrange( new Rect( new Point( 0, 0 ), child.DesiredSize ) );
}
return finalSize;
}
示例12: MeasureOverride
//-------------------------------------------------------------------
//
// Protected Methods
//
//-------------------------------------------------------------------
#region Protected Methods
/// <summary>
/// Content measurement.
/// </summary>
/// <param name="constraint">Constraint size.</param>
/// <returns>Computed desired size.</returns>
protected sealed override Size MeasureOverride(Size constraint)
{
Size desiredSize = new Size();
if (_suspendLayout)
{
desiredSize = this.DesiredSize;
}
else if (Document != null)
{
// Create bottomless formatter, if necessary.
EnsureFormatter();
// Format bottomless content.
_formatter.Format(constraint);
// DesiredSize is set to the calculated size of the page.
// If hosted by ScrollViewer, desired size is limited to constraint.
if (_scrollData != null)
{
desiredSize.Width = Math.Min(constraint.Width, _formatter.DocumentPage.Size.Width);
desiredSize.Height = Math.Min(constraint.Height, _formatter.DocumentPage.Size.Height);
}
else
{
desiredSize = _formatter.DocumentPage.Size;
}
}
return desiredSize;
}
示例13: MeasureOverride
protected override Size MeasureOverride(Size availableSize)
{
onPreApplyTemplate();
Size theChildSize = getItemSize();
foreach (UIElement child in Children)
{
child.Measure(theChildSize);
}
int childrenPerRow;
// Figure out how many children fit on each row
if (availableSize.Width == Double.PositiveInfinity)
{
childrenPerRow = this.Children.Count;
}
else
{
childrenPerRow = Math.Max(1, (int)Math.Floor(availableSize.Width / this.ItemWidth));
}
// Calculate the width and height this results in
double width = childrenPerRow * this.ItemWidth;
var fudge = (width - childrenPerRow * ItemWidth) / childrenPerRow;
double height = (this.ItemHeight +fudge )* (Math.Floor((double)(this.Children.Count +childrenPerRow - 1) / childrenPerRow) );
height = (height.IsValid()) ? height : 0;
return new Size(width, height);
}
示例14: OnSourceInitialized
/// <inheritdoc/>
protected override void OnSourceInitialized(EventArgs e) {
base.OnSourceInitialized(e);
var hwndSource = PresentationSource.FromVisual(this) as HwndSource;
Debug.Assert(hwndSource != null);
if (hwndSource != null) {
hwndSource.AddHook(WndProc);
wpfDpi = new Size(96.0 * hwndSource.CompositionTarget.TransformToDevice.M11, 96.0 * hwndSource.CompositionTarget.TransformToDevice.M22);
var w = Width;
var h = Height;
WindowDpi = GetDpi(hwndSource.Handle) ?? wpfDpi;
// For some reason, we can't initialize the non-fit-to-size property, so always force
// manual mode. When we're here, we should already have a valid Width and Height
Debug.Assert(h > 0 && !double.IsNaN(h));
Debug.Assert(w > 0 && !double.IsNaN(w));
SizeToContent = SizeToContent.Manual;
if (!wpfSupportsPerMonitorDpi) {
double scale = DisableDpiScalingAtStartup ? 1 : WpfPixelScaleFactor;
Width = w * scale;
Height = h * scale;
if (WindowStartupLocation == WindowStartupLocation.CenterOwner || WindowStartupLocation == WindowStartupLocation.CenterScreen) {
Left -= (w * scale - w) / 2;
Top -= (h * scale - h) / 2;
}
}
}
WindowUtils.UpdateWin32Style(this);
}
示例15: MeasureOverride
protected override Size MeasureOverride (Size availableSize)
{
Tester.WriteLine ("MeasureOverride input = " + availableSize.ToString ());
Size output = base.MeasureOverride (availableSize);
Tester.WriteLine ("MeasureOverride output = " + output.ToString ());
return output;
}