since wpf relies on xaml as its UI layer, which doesn't support any type safety, is it ok to use c# 8's Nullable reference types with wpf ?
Nullable reference types are not new types, instead, they are original reference types with some attributes for compiler to check. In other words, nullable reference types will do nothing different in runtime.
In all view types in the code behind files (_*.xaml.cs_) add #nullable disable on top, otherwise it won't work, and will issue errors such as this one:
Partial declarations of ‘MainWindow’ must not specify different base classes
I reported it here too.
@grubioe I don't think it's a issue-type-question label type but rather an issue/bug that needs taking care of.
This is definitely a bug, albeit with a somewhat useful workaround.
From what I can tell, the temp project used for MarkupCompilePass2 is not properly working when nullable is being used. I took a quick look at the generated code files, but I didn't see anything that would indicate the base classes were not the same.
If I create a basic project that doesn't use generics to define its MainWindow class, this worked fine. So there has to be some specific code-generation problem in the generic path that is causing this.
In any case, I am going to move this to the bug backlog for .NET 5.
Will this be fixed in .Net 5.0? It isn't assigned to any milestone.
In all view types in the code behind files (_*.xaml.cs_) add
#nullable disableon top, otherwise it won't work
If you want to use nullable as much as possible, it's possible to do this:
using ReactiveUI;
namespace Something
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
#nullable disable
public partial class MainWindow : ReactiveWindow<MainViewModel>
#nullable enable
{
// Rest of class
}
}