내보내기(0) 인쇄
모두 확장

UIElement.DesiredSize 속성

Gets the size that this element computed during the measure pass of the layout process.

네임스페이스: System.Windows
어셈블리: PresentationCore(presentationcore.dll)
XML 네임스페이스:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public Size DesiredSize { get; }
/** @property */
public Size get_DesiredSize ()

public function get DesiredSize () : Size

이 속성은 XAML에서 사용할 수 없습니다.

속성 값

The computed size, which becomes the desired size for the arrange pass.

The value returned by this property will only be a valid measurement if the value of the IsMeasureValid property is true.

DesiredSize is typically checked as one of the measurement factors when you implement layout behavior overrides such as ArrangeOverride, MeasureOverride or OnRender. Depending on the scenario, DesiredSize might be fully respected by your implementation logic, constraints on DesiredSize might be applied, and such constraints might also change other characteristics of either the parent element or child element. For example, a control that supports scrollable regions (but chooses not to derive from the WPF framework-level controls that already enable scrollable regions) could compare available size to DesiredSize. The control could then set an internal state that enabled scrollbars in the UI for that control. Or, DesiredSize could potentially also be ignored in certain scenarios.

The following example shows how a custom adorner uses the DesiredSize value in order to create and size the rectangle graphic that defines the adorner, as part of its OnRender implementation.

protected override void OnRender(DrawingContext drawingContext)
{
  // Get a rectangle that represents the desired size of the rendered element
  // after the rendering pass.  This will be used to draw at the corners of the 
  // adorned element.
  Rect adornedElementRect = new Rect(this.AdornedElement.DesiredSize);

  // Some arbitrary drawing implements.
  SolidColorBrush renderBrush = new SolidColorBrush(Colors.Green);
  renderBrush.Opacity = 0.2;
  Pen renderPen = new Pen(new SolidColorBrush(Colors.Navy), 1.5);
  double renderRadius = 5.0;

  // Just draw a circle at each corner.
  drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopLeft, renderRadius, renderRadius);
  drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopRight, renderRadius, renderRadius);
  drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
  drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomRight, renderRadius, renderRadius);
}

Microsoft .NET Framework 3.0은 Windows Vista, Microsoft Windows XP SP2 및 Windows Server 2003 SP1에서 지원됩니다.

.NET Framework

3.0에서 지원

커뮤니티 추가 항목

추가
Microsoft는 MSDN 웹 사이트에 대한 귀하의 의견을 이해하기 위해 온라인 설문 조사를 진행하고 있습니다. 참여하도록 선택하시면 MSDN 웹 사이트에서 나가실 때 온라인 설문 조사가 표시됩니다.

참여하시겠습니까?
표시:
© 2014 Microsoft