Example #1
0
 /// <summary>
 /// Returns a <see cref="Media.Rectangle"/> that represents the layout partition that is reserved for a child element<para></para>
 /// It is equivalent to the rectangle returned by the <see cref="IUIElement.RenderTarget"/> property, modified to include eventual padding values
 /// </summary>
 /// <param name="element">The <see cref="IUIElement"/> instance to compute the layout slot of</param>
 /// <returns>A <see cref="Media.Rectangle"/> that represents the layout partition that is reserved for a child element</returns>
 public static Media.Rectangle GetLayoutSlot(IUIElement element)
 {
     IPaddedElement paddedElement;
     Media.Point layoutSlotPosition;
     Media.Size layoutSlotSize;
     Media.Rectangle layoutSlot;
     layoutSlotPosition = element.RenderTarget.Position;
     layoutSlotSize = element.RenderTarget.Size;
     if (typeof(IPaddedElement).IsAssignableFrom(element.GetType()))
     {
         paddedElement = (IPaddedElement)element;
         layoutSlotPosition += new Media.Point(paddedElement.Padding.Left, paddedElement.Padding.Top);
         layoutSlotSize = new Media.Size(layoutSlotSize.Width - paddedElement.Padding.Left - paddedElement.Padding.Right, layoutSlotSize.Height - paddedElement.Padding.Top - paddedElement.Padding.Bottom );
     }
     layoutSlot = new Media.Rectangle(layoutSlotPosition, layoutSlotSize);
     return layoutSlot;
 }
Example #2
0
 /// <summary>
 /// When overriden in a class, this method allows the execution of code whenever the element has been rendered
 /// </summary>
 ///<param name="drawingContext">The <see cref="DrawingContext"/> in which the element has been rendered</param>
 protected override void OnRender(DrawingContext drawingContext)
 {
     Media.Size textSize;
     Media.Rectangle layoutSlot;
     if (!string.IsNullOrWhiteSpace(this.Text)
         && this.Foreground != null)
     {
         textSize = DrawingContext.MeasureText(this.Text, this.Font);
         layoutSlot = LayoutInformation.GetLayoutSlot(this);
         layoutSlot = new Media.Rectangle(new Media.Point(layoutSlot.Position.X - textSize.Width / 2, layoutSlot.Position.Y - textSize.Height / 2), layoutSlot.Size);
         drawingContext.DrawText(this.Text, layoutSlot.Position, this.Font, this.Foreground);
     }
 }