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.
On which page? π
https://platform.uno/docs/articles/migrating-to-uno-7.html (section "Members restricted to their WinUI declaring types", the
DataContextentry, and migration checklist item 15)What's wrong? β
The 7.0 guide explains that
DataContextnow lives onFrameworkElementonly, but it does not mention that the property is now declared as nullable:public object? DataContext. Before, it was emitted by theDependencyObjectsource generator as a plainobject(no nullable annotation).The nullable annotation is the correct one (the default is
null, andDataContext = nullis valid), but it surfaces as new compiler warnings in code that was clean on 6.x: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 passingDataContextto a non-nullable parameter). The guide already documents a similar case forUno0001andTreatWarningsAsErrors, so there is precedent for a note.Verified by code inspection on
master(c83e458):src/Uno.UI/UI/Xaml/FrameworkElement.DataContext.csdeclarespublic object? DataContext, anddoc/articles/migrating-to-uno-7.mdhas no mention of nullable annotations orDataContextnullability.Any feedback? π¬
Suggested addition to the
DataContextbullet and checklist item 15: "FrameworkElement.DataContextis now annotatedobject?. With nullable reference types enabled, reads that flow into a non-nullableobjectproduceCS8600/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
TreatWarningsAsErrorsprojects.