Table of Contents

Class ContentPresenter

Namespace
Icy.UI.Controls
Assembly
IcyUI.dll

Marks the spot inside a ControlTemplate's content where a ContentControl's real Content should be hosted.

[ContentProperty("Content")]
public class ContentPresenter : UIElement, INotifyPropertyChanging, IBindingTarget, INotifyPropertyChanged, INotifyFocusChanged, IContainerLayout
Inheritance
ContentPresenter
Implements
Inherited Members
Extension Methods

Remarks

A pure passthrough host - no background, border, or padding-band decoration of its own (unlike Border, which it otherwise mirrors closely). Typically wired as <ContentPresenter Content="{TemplateBinding Content}"/> inside a template.

Properties

Content

Gets or sets the element this presenter hosts.

public UIElement? Content { get; set; }

Property Value

UIElement

ContentBounds

Gets the area available to Content, i.e. ActualBounds inset by Padding.

public Rectangle ContentBounds { get; }

Property Value

Rectangle

Methods

ArrangeContent()

Handles custom arrange logic when overridden in any UIElement instance.

protected override void ArrangeContent()

Remarks

This method is called during the arrange pass to position and size the element's content within its final bounds. The element's position and size are already determined by the layout system and available in the ActualBounds property.

When implementing this method:

  • Position child elements within the available space;
  • Respect the element's padding when positioning content;
  • Handle any content-specific layout requirements;
  • Call Arrange() on child elements if needed.

GetVisualChildren()

Enumerates this element's immediate visual children, in paint order (back-to-front), for hit-testing and tree traversal.

protected override IEnumerable<UIElement> GetVisualChildren()

Returns

IEnumerable<UIElement>

The element's immediate children. The base implementation yields none (a leaf element).

Remarks

Container elements (e.g. Panel, Border) override this to expose their children, in the exact order they're drawn in — HitTest(Vector2) depends on this matching actual paint order, or clicks will target the wrong, visually-obscured element.

MeasureContent()

Handles custom measure logic when overridden in any UIElement instance.

protected override Size MeasureContent()

Returns

Size

Size recommended to display the UIElement.

Remarks

This method is called during the measure pass to determine the desired size of the element. The returned size should represent the natural size of the element's content, without considering any constraints, margins, or padding.

When implementing this method:

  • Return the natural size needed to display the content;
  • Do not include padding, margins, or borders in the returned size;
  • Consider the content's actual dimensions (e.g., text length, image size);
  • Return Empty if the element has no content.

OnRender(IRenderContext)

Handles custom render logic when overridden in any UIElement instance.

protected override void OnRender(IRenderContext context)

Parameters

context IRenderContext

The context to render with.