Skip to content

Conversation

Copy link

Copilot AI commented Jan 20, 2026

EditorField crashes with NullReferenceException when FontFamily is set via implicit style. The property callback attempts to access labelTitle and EditorView before control template application during construction.

Changes

  • EditorField.BindableProperties.cs: Add null checks in FontFamilyProperty callback before accessing EditorView and labelTitle
  • InputField.cs: Add null check in FontAutoScalingEnabledProperty callback before accessing labelTitle (same root cause)
  • EditorField_Test.cs: Add test coverage for implicit style application and direct property setting

Example

Before this fix, the following XAML would crash on initialization:

<Style TargetType="material:EditorField">
    <Setter Property="FontFamily" Value="OpenSansSemibold" />
</Style>

The callback now defers property application until the visual tree elements exist:

if (editorField.EditorView != null)
{
    editorField.EditorView.FontFamily = (string)newValue;
}

if (editorField.labelTitle != null)
{
    editorField.labelTitle.FontFamily = (string)newValue;
}
Original prompt

This section details on the original issue you should resolve

<issue_title>NullReferenceException when EditorField uses a implicit Style with FontFamily</issue_title>
<issue_description>### Summary
A NullReferenceException occurs during control initialization when an implicit Style targeting material:EditorField defines the FontFamily property.
The exception is thrown while styles are being applied, before any user interaction.

Affected Versions

  • UraniumUI: 2.14.0 (last known working version: 2.9.1)

Steps to Reproduce

  1. Define an implicit style for material:EditorField in Styles.xaml that sets FontFamily
  2. Instantiate an EditorField in any page
  3. Run the application

A minimal reproduction is available here:
https://github.com/idenardi/uraniumui-editorfield-style

Style Example

<Style TargetType="material:EditorField">
    <Setter Property="FontFamily" Value="OpenSansSemibold" />
</Style>

Actual Behavior

The application crashes with a NullReferenceException during EditorField initialization.

Stacktrace (partial)

System.NullReferenceException: Object reference not set to an instance of an object
   at UraniumUI.Material.Controls.EditorField.<>c.<.cctor>b__64_1(...)
   at Microsoft.Maui.Controls.Setter.Apply(...)
   at Microsoft.Maui.Controls.Style.ApplyCore(...)
   ...
   at UraniumUI.Material.Controls.EditorField..ctor()

Workaround

Removing the FontFamily setter from the implicit EditorField style prevents the crash.
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…FontFamily

- Add null checks to EditorField.FontFamilyProperty callback
- Add null checks to InputField.FontAutoScalingEnabledProperty callback
- Add tests for FontFamily property initialization via implicit styles

Co-authored-by: enisn <23705418+enisn@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix NullReferenceException with implicit Style on EditorField Fix NullReferenceException when EditorField uses implicit Style with FontFamily Jan 20, 2026
Copilot AI requested a review from enisn January 20, 2026 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullReferenceException when EditorField uses a implicit Style with FontFamily

2 participants