stride3d/stride · error · InvalidOperationException
A part named 'PART_TrimmedText' must be present in the Contr
Error message
A part named 'PART_TrimmedText' must be present in the ControlTemplate, and must be of type 'TextBlock'.
What it means
The Stride TextBox custom control requires its ControlTemplate to contain a named part 'PART_TrimmedText' of type TextBlock, used to render a trimmed/ellipsis version of the text. During OnApplyTemplate the control looks this part up via GetTemplateChild; if the template omits it or provides a different element type, the cast yields null and the control throws InvalidOperationException. This enforces the WPF template-part contract so the control's visual logic always has the elements it depends on.
Solutions
- Add <TextBlock x:Name="PART_TrimmedText"/> to the custom ControlTemplate.
- Ensure the element named PART_TrimmedText is a TextBlock, not another element type.
- If not customizing visuals, remove the custom Style so the library's default template is used.
Example fix
// before (custom template missing part)
<Style TargetType="controls:TextBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:TextBox">
<Border><ScrollViewer x:Name="PART_ContentHost"/></Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
// after
<ControlTemplate TargetType="controls:TextBox">
<Border>
<ScrollViewer x:Name="PART_ContentHost"/>
<TextBlock x:Name="PART_TrimmedText" TextTrimming="CharacterEllipsis"/>
</Border>
</ControlTemplate> Defensive patterns
Strategy: validation
Validate before calling
// In template resource review, assert required parts exist before applying:
var tb = template.FindName("PART_TrimmedText", templatedParentScope) as TextBlock;
if (tb == null) throw new InvalidOperationException("Template must contain TextBlock named PART_TrimmedText"); Type guard
bool HasTrimmedTextPart(ControlTemplate t, FrameworkElement scope) =>
scope != null && scope.FindName("PART_TrimmedText", scope) is TextBlock; Try / catch
try { element.ApplyTemplate(); } catch (InvalidOperationException ex) when (ex.Message.Contains("PART_TrimmedText")) { /* restore default template or log template contract violation */ } Prevention
- When copying a default template, diff it against the original to keep all PART_ named parts.
- Add a unit/style smoke test that instantiates the control and calls ApplyTemplate with your custom template.
- Never rename PART_* parts in custom templates; they are a public contract.
When it happens
Trigger: Applying a custom ControlTemplate to this TextBox control that lacks an element named 'PART_TrimmedText', or names it but the element is not a TextBlock (e.g. a Border or ContentPresenter). Also triggered when the default template resource fails to load so OnApplyTemplate runs against an empty/partial template.
Common situations: Developers restyling the control with a new Style/ControlTemplate and forgetting to copy required named parts; renaming the part in a copied template; theming resources missing after a library upgrade.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- A part named '{GridPartName}' must be present in the Control
- A part named 'PART_EditableTextBox' must be present in the C
- A part named 'PART_ListBox' must be present in the ControlTe
- A part named 'PART_LogTextBox' must be present in the Contro
- A part named 'PART_LogGridView' must be present in the Contr
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/f1ef5f6e66e63e60.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Presentation.Wpf/Controls/TextBox.cs:85
/// Gets or sets the amount of time before a validation of input text happens, in milliseconds.
/// Every change to the <see cref="TextBox.Text"/> property reset the timer to this value.
/// </summary>
/// <remarks>The default value is <c>500</c> milliseconds.</remarks>
public int ValidationDelay { get { return (int)GetValue(ValidationDelayProperty); } set { SetValue(ValidationDelayProperty, value); } }
/// <summary>
/// Gets the trimmed text to display when the control does not have the focus, depending of the value of the <see cref="TextTrimming"/> property.
/// </summary>
public string TrimmedText { get { return (string)GetValue(TrimmedTextPropertyKey.DependencyProperty); } private set { SetValue(TrimmedTextPropertyKey, value); } }
/// <inheritdoc/>
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
trimmedTextBlock = GetTemplateChild("PART_TrimmedText") as TextBlock;
if (trimmedTextBlock == null)
throw new InvalidOperationException("A part named 'PART_TrimmedText' must be present in the ControlTemplate, and must be of type 'TextBlock'.");
}
/// <summary>
/// Raised when the text of the TextBox changes.
/// </summary>
/// <param name="oldValue">The old value of the <see cref="TextBox.Text"/> property.</param>
/// <param name="newValue">The new value of the <see cref="TextBox.Text"/> property.</param>
protected override void OnTextChanged(string oldValue, string newValue)
{
if (UseTimedValidation)
{
if (ValidationDelay > 0.0)
{
validationTimer?.Change(ValidationDelay, Timeout.Infinite);
}
else
{
Validate();View on GitHub (pinned to 96fad776d2)