Skip to content

Uno 7 migration guide does not mention that FrameworkElement.DataContext is now nullable (object?)Β #24875

Description

@MartinZikmund

On which page? πŸ“„

https://platform.uno/docs/articles/migrating-to-uno-7.html (section "Members restricted to their WinUI declaring types", the DataContext entry, and migration checklist item 15)

What's wrong? ❗

The 7.0 guide explains that DataContext now lives on FrameworkElement only, but it does not mention that the property is now declared as nullable: public object? DataContext. Before, it was emitted by the DependencyObject source generator as a plain object (no nullable annotation).

The nullable annotation is the correct one (the default is null, and DataContext = null is valid), but it surfaces as new compiler warnings in code that was clean on 6.x:

FrameworkElement fe = ...;
object x = fe.DataContext;   // CS8600: Converting null literal or possible null value to non-nullable type
Foo(fe.DataContext);         // CS8604: Possible null reference argument (when Foo takes a non-nullable object)

For projects with <Nullable>enable</Nullable> and <TreatWarningsAsErrors>true</TreatWarningsAsErrors> (or <WarningsAsErrors>nullable</WarningsAsErrors>) this becomes a build break after the upgrade, with no hint in the guide. We hit it while retargeting a library to 7.0.0-dev.645 (CS8604 at a call site passing DataContext to a non-nullable parameter). The guide already documents a similar case for Uno0001 and TreatWarningsAsErrors, so there is precedent for a note.

Verified by code inspection on master (c83e458): src/Uno.UI/UI/Xaml/FrameworkElement.DataContext.cs declares public object? DataContext, and doc/articles/migrating-to-uno-7.md has no mention of nullable annotations or DataContext nullability.

Any feedback? πŸ’¬

Suggested addition to the DataContext bullet and checklist item 15: "FrameworkElement.DataContext is now annotated object?. With nullable reference types enabled, reads that flow into a non-nullable object produce CS8600/CS8604. Null-check, use !, or pattern-match (if (fe.DataContext is MyViewModel vm))."

Optionally, add a short general note that nullable annotation changes in 7.0 can surface as warnings in TreatWarningsAsErrors projects.

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

difficulty/starter πŸš€Categorizes an issue for which the difficulty level is reachable by newcomersgood first issueDenotes an issue ready for a new contributor, according to the "help wanted" guidelines.kind/consumer-experiencekind/documentationplatform/allCategorizes an issue or PR as relevant to the all platformsproject/documentation πŸ“–Categorizes an issue or PR as relevant to documentationtriage/untriagedIndicates an issue requires triaging or verification

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions