docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class ClampedContent

    Caps tall content at a maximum height and reveals the rest behind a Show more / Show less toggle.

    Inheritance
    object
    CallbackEventHandler
    Focusable
    VisualElement
    BaseVisualElement
    ClampedContent
    Implements
    IEventHandler
    IResolvedStyle
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    IContextOverrideElement
    IAdditionalDataHolder
    Inherited Members
    BaseVisualElement.contextPrefix
    BaseVisualElement.densityOverride
    BaseVisualElement.themeOverride
    BaseVisualElement.langOverride
    BaseVisualElement.layoutDirectionOverride
    BaseVisualElement.preferredTooltipPlacementOverride
    BaseVisualElement.tooltipDelayMsOverride
    BaseVisualElement.GetLayoutDirectionUssClassName(Dir)
    VisualElement.disabledUssClassName
    VisualElement.SetActivePseudoState(bool)
    VisualElement.SetCheckedPseudoState(bool)
    VisualElement.Focus()
    VisualElement.SendEvent(EventBase)
    VisualElement.SetEnabledFromHierarchy(bool)
    VisualElement.SetEnabled(bool)
    VisualElement.MarkDirtyRepaint()
    VisualElement.IsMarkedForRepaint()
    VisualElement.ContainsPoint(Vector2)
    VisualElement.Overlaps(Rect)
    VisualElement.DoMeasure(float, VisualElement.MeasureMode, float, VisualElement.MeasureMode)
    VisualElement.ToString()
    VisualElement.GetClasses()
    VisualElement.ClearClassList()
    VisualElement.AddToClassList(string)
    VisualElement.RemoveFromClassList(string)
    VisualElement.ToggleInClassList(string)
    VisualElement.EnableInClassList(string, bool)
    VisualElement.ClassListContains(string)
    VisualElement.FindAncestorUserData()
    VisualElement.SetBinding(BindingId, Binding)
    VisualElement.GetBinding(BindingId)
    VisualElement.TryGetBinding(BindingId, out Binding)
    VisualElement.GetBindingInfos()
    VisualElement.GetBindingInfos(List<BindingInfo>)
    VisualElement.HasBinding(BindingId)
    VisualElement.ClearBinding(BindingId)
    VisualElement.ClearBindings()
    VisualElement.GetHierarchicalDataSourceContext()
    VisualElement.GetDataSourceContext(BindingId)
    VisualElement.TryGetDataSourceContext(BindingId, out DataSourceContext)
    VisualElement.TryGetLastBindingToUIResult(in BindingId, out BindingResult)
    VisualElement.TryGetLastBindingToSourceResult(in BindingId, out BindingResult)
    VisualElement.Add(VisualElement)
    VisualElement.Insert(int, VisualElement)
    VisualElement.Remove(VisualElement)
    VisualElement.RemoveAt(int)
    VisualElement.Clear()
    VisualElement.ElementAt(int)
    VisualElement.IndexOf(VisualElement)
    VisualElement.Children()
    VisualElement.Sort(Comparison<VisualElement>)
    VisualElement.BringToFront()
    VisualElement.SendToBack()
    VisualElement.PlaceBehind(VisualElement)
    VisualElement.PlaceInFront(VisualElement)
    VisualElement.RemoveFromHierarchy()
    VisualElement.GetFirstOfType<T>()
    VisualElement.GetFirstAncestorOfType<T>()
    VisualElement.Contains(VisualElement)
    VisualElement.FindCommonAncestor(VisualElement)
    VisualElement.viewDataKey
    VisualElement.userData
    VisualElement.canGrabFocus
    VisualElement.focusController
    VisualElement.disablePlayModeTint
    VisualElement.usageHints
    VisualElement.transform
    VisualElement.scaledPixelsPerPoint
    VisualElement.layout
    VisualElement.contentRect
    VisualElement.paddingRect
    VisualElement.worldBound
    VisualElement.localBound
    VisualElement.worldTransform
    VisualElement.hasActivePseudoState
    VisualElement.hasInactivePseudoState
    VisualElement.hasHoverPseudoState
    VisualElement.hasCheckedPseudoState
    VisualElement.hasEnabledPseudoState
    VisualElement.hasDisabledPseudoState
    VisualElement.hasFocusPseudoState
    VisualElement.hasRootPseudoState
    VisualElement.pickingMode
    VisualElement.name
    VisualElement.enabledInHierarchy
    VisualElement.enabledSelf
    VisualElement.languageDirection
    VisualElement.visible
    VisualElement.generateVisualContent
    VisualElement.dataSource
    VisualElement.dataSourcePath
    VisualElement.dataSourceType
    VisualElement.experimental
    VisualElement.hierarchy
    VisualElement.cacheAsBitmap
    VisualElement.parent
    VisualElement.panel
    VisualElement.visualTreeAssetSource
    VisualElement.this[int]
    VisualElement.childCount
    VisualElement.schedule
    VisualElement.style
    VisualElement.resolvedStyle
    VisualElement.customStyle
    VisualElement.styleSheets
    VisualElement.tooltip
    Focusable.Blur()
    Focusable.focusable
    Focusable.tabIndex
    Focusable.delegatesFocus
    CallbackEventHandler.RegisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.RegisterCallbackOnce<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)
    CallbackEventHandler.RegisterCallbackOnce<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)
    CallbackEventHandler.RegisterCallback<TEventType>(EventCallback<TEventType>, CallbackOptions)
    CallbackEventHandler.RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, CallbackOptions)
    CallbackEventHandler.UnregisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.UnregisterCallback<TEventType>(EventCallback<TEventType>, CallbackOptions)
    CallbackEventHandler.UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TrickleDown)
    CallbackEventHandler.UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, CallbackOptions)
    CallbackEventHandler.UnregisterAllRemovableCallbacks()
    CallbackEventHandler.HasTrickleDownHandlers()
    CallbackEventHandler.HasBubbleUpHandlers()
    CallbackEventHandler.ExecuteDefaultActionAtTarget(EventBase)
    CallbackEventHandler.HandleEventBubbleUp(EventBase)
    CallbackEventHandler.HandleEventTrickleDown(EventBase)
    CallbackEventHandler.ExecuteDefaultAction(EventBase)
    CallbackEventHandler.NotifyPropertyChanged(in BindingId)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Unity.AppUI.UI
    Assembly: Unity.AppUI.dll
    Syntax
    [UxmlElement]
    public class ClampedContent : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
    Remarks

    Add any content to a ClampedContent and it measures it on every layout pass. While the content is shorter than maxHeight the element is completely transparent — no toggle, no fade, no clipping. Once it overflows, the body is clipped, a fade sits over the cut edge and the toggle appears.

    This clamps by height, not by line count. That mirrors the registry component, which uses a max-h-* cap rather than -webkit-line-clamp; UI Toolkit has no line-clamp either, so the two implementations agree. To cap at roughly N lines, set maxHeight to N times the content's line height.

    The cap lives on the clipping viewport and the measurement reads the container inside it, which keeps its natural height whether or not it is clipped. That is why measurement can run in both states here, where the web component has to skip it while expanded: with the cap off, a DOM measurement reads "not overflowing" and the toggle vanishes, stranding the user expanded. The registry's contentKey prop exists for the same reason and is not needed either, since UI Toolkit re-runs layout on any child change. Call Remeasure() only after replacing the content outside a layout pass.

    The fade is a vertical gradient from transparent to the colour set by the --clamped-content-fade-color custom USS property on the fade element (the default surface colour by default). USS has no linear-gradient, so it is drawn as a vertex-coloured mesh. Override the property when the host surface is not the default background, or set fadeVisible to false.

    Examples

    Clamping a long description in UXML.

    <appui:ClampedContent max-height="120">
        <appui:Text text="A very long description that runs well past the cap..." />
    </appui:ClampedContent>

    Clamping in C# with custom labels.

    var clamped = new ClampedContent
    {
        maxHeight = 200f,
        moreLabel = "Read more",
        lessLabel = "Collapse",
    };
    clamped.Add(new Text { text = logOutput });
    clamped.expandedChanged += expanded => Debug.Log($"expanded: {expanded}");

    Constructors

    ClampedContent()

    Default constructor.

    Declaration
    public ClampedContent()

    Fields

    containerUssClassName

    The styling class of the container the content actually lives in.

    Declaration
    public const string containerUssClassName = "appui-clamped-content__container"
    Field Value
    Type Description
    string

    defaultMaxHeight

    The default height cap, in pixels.

    Declaration
    public const float defaultMaxHeight = 320
    Field Value
    Type Description
    float
    Remarks

    Mirrors the registry's max-h-80 default. It is a literal because it is a per-use content budget, not a design token — no App UI sizing step is anywhere near this tall.

    expandedUssClassName

    The styling class applied while the content is expanded.

    Declaration
    public const string expandedUssClassName = "appui-clamped-content--expanded"
    Field Value
    Type Description
    string

    fadeUssClassName

    The styling class of the fade drawn over the clipped edge.

    Declaration
    public const string fadeUssClassName = "appui-clamped-content__fade"
    Field Value
    Type Description
    string

    overflowingUssClassName

    The styling class applied while the content actually overflows.

    Declaration
    public const string overflowingUssClassName = "appui-clamped-content--overflowing"
    Field Value
    Type Description
    string

    toggleUssClassName

    The styling class of the Show more / Show less toggle.

    Declaration
    public const string toggleUssClassName = "appui-clamped-content__toggle"
    Field Value
    Type Description
    string

    ussClassName

    The ClampedContent main styling class.

    Declaration
    public const string ussClassName = "appui-clamped-content"
    Field Value
    Type Description
    string

    viewportUssClassName

    The styling class of the clipping viewport.

    Declaration
    public const string viewportUssClassName = "appui-clamped-content__viewport"
    Field Value
    Type Description
    string

    Properties

    contentContainer

    Logical container where child elements are added. If a child is added to this element, the child is added to this element's content container instead.

    Declaration
    public override VisualElement contentContainer { get; }
    Property Value
    Type Description
    VisualElement
    Overrides
    VisualElement.contentContainer

    expanded

    Whether the content is currently revealed in full.

    Declaration
    [Tooltip("Whether the content is currently revealed in full.")]
    [CreateProperty]
    [UxmlAttribute]
    public bool expanded { get; set; }
    Property Value
    Type Description
    bool
    Remarks

    Setting this drives the same state the toggle does, so a host can expand the block from elsewhere — a "expand all" command, for instance.

    fadeVisible

    Whether the fade is drawn over the clipped edge while collapsed and overflowing.

    Declaration
    [Tooltip("Whether the fade is drawn over the clipped edge.")]
    [CreateProperty]
    [UxmlAttribute]
    public bool fadeVisible { get; set; }
    Property Value
    Type Description
    bool

    lessLabel

    The toggle's label while expanded. Accepts a localization key.

    Declaration
    [Tooltip("The toggle's label while expanded.")]
    [CreateProperty]
    [UxmlAttribute]
    public string lessLabel { get; set; }
    Property Value
    Type Description
    string

    maxHeight

    The height cap applied while collapsed, in pixels.

    Declaration
    [Tooltip("The height cap applied while collapsed, in pixels.")]
    [CreateProperty]
    [UxmlAttribute]
    public float maxHeight { get; set; }
    Property Value
    Type Description
    float

    moreLabel

    The toggle's label while collapsed. Accepts a localization key.

    Declaration
    [Tooltip("The toggle's label while collapsed.")]
    [CreateProperty]
    [UxmlAttribute]
    public string moreLabel { get; set; }
    Property Value
    Type Description
    string

    overflowing

    Whether the content is taller than maxHeight.

    Declaration
    public bool overflowing { get; }
    Property Value
    Type Description
    bool
    Remarks

    Read-only, and re-evaluated on every layout pass while collapsed. While expanded it keeps the value measured just before expanding.

    Methods

    Remeasure()

    Re-measures the content against maxHeight and updates the toggle and the fade.

    Declaration
    public void Remeasure()
    Remarks

    This runs automatically on attach and on every layout change. Call it directly only after swapping the content outside a layout pass. It is correct in both states: what is measured is the uncapped container, not the clipping viewport.

    Events

    expandedChanged

    Raised when expanded changes, by toggle or programmatically.

    Declaration
    public event Action<bool> expandedChanged
    Event Type
    Type Description
    Action<bool>

    Implements

    IEventHandler
    IResolvedStyle
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    IContextOverrideElement
    IAdditionalDataHolder

    Extension Methods

    VisualElementExtensions.FindNavController(VisualElement)
    RegisterUpdateCallbackExtensions.RegisterUpdateCallback(VisualElement, EventCallback<UpdateEvent>)
    RegisterUpdateCallbackExtensions.UnregisterUpdateCallback(VisualElement, EventCallback<UpdateEvent>)
    VisualElementExtensions.EnableDynamicTransform(VisualElement, bool)
    VisualElementExtensions.EnablePicking(VisualElement, bool)
    VisualElementExtensions.GetChildren<T>(VisualElement, bool)
    VisualElementExtensions.GetContextProvider<T>(VisualElement)
    VisualElementExtensions.GetContextProvider<T>(VisualElement, string)
    VisualElementExtensions.GetContext<T>(VisualElement)
    VisualElementExtensions.GetContext<T>(VisualElement, string)
    VisualElementExtensions.GetExclusiveRootElement(VisualElement)
    VisualElementExtensions.GetLastAncestorOfType<T>(VisualElement)
    VisualElementExtensions.GetPreferredTooltipPlacement(VisualElement)
    VisualElementExtensions.GetSelfContext<T>(VisualElement)
    VisualElementExtensions.GetSelfContext<T>(VisualElement, string)
    VisualElementExtensions.GetTooltipContent(VisualElement)
    VisualElementExtensions.GetTooltipTemplate(VisualElement)
    VisualElementExtensions.HasAncestorOfType<T>(VisualElement, bool)
    VisualElementExtensions.HasAncestorsOfType<T>(VisualElement)
    VisualElementExtensions.IsContextProvider<T>(VisualElement)
    VisualElementExtensions.IsContextProvider<T>(VisualElement, string)
    VisualElementExtensions.IsInvisible(VisualElement)
    VisualElementExtensions.IsOnScreen(VisualElement)
    VisualElementExtensions.ProvideContext<T>(VisualElement, string, T)
    VisualElementExtensions.ProvideContext<T>(VisualElement, T)
    VisualElementExtensions.RegisterContextChangedCallback<T>(VisualElement, string, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.RegisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.SetPreferredTooltipPlacement(VisualElement, OptionalEnum<PopoverPlacement>)
    VisualElementExtensions.SetTooltipContent(VisualElement, VisualElementExtensions.TooltipContentCallback)
    VisualElementExtensions.SetTooltipTemplate(VisualElement, VisualElement)
    VisualElementExtensions.UnregisterContextChangedCallback<T>(VisualElement, string, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.UnregisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)