wpf icon indicating copy to clipboard operation
wpf copied to clipboard

Non existing event subscriptions should raise a build error

Open Symbai opened this issue 7 months ago • 6 comments

If you subscribe to any event in XAML (like KeyDown) but the method doesn't exist in your C# code, you can still successfully build your project. But if you run it and the XAML is executed your application crashes.

And because of the fact that it crashes the application (unlike a non existing binding) it should be analyzed and throw an error during the build.

Symbai avatar Apr 19 '25 05:04 Symbai

I think the main issues it perform the runtime bind the event.

lindexi avatar Apr 21 '25 11:04 lindexi

I'm sorry but what do you mean?

Symbai avatar Apr 21 '25 11:04 Symbai

The xaml can not check more thing in the build time.

lindexi avatar Apr 21 '25 11:04 lindexi

Why not? Other XAML frameworks do, and this would make future X:Bind support (compiled bindings) easier

franchyd avatar Apr 21 '25 15:04 franchyd

@franchyd Yes, you are right. If we can bring the xaml to build time, such as SourceGenerator, that we can handle this issues. And bring the SourceGenerator to xaml is what I look to.

lindexi avatar Apr 22 '25 00:04 lindexi

Well technically developers do not need to rely on the built-in InitializeComponents and could handle the XAML themselves. Not saying that many (or any) do, but it could be potentially breaking change.

miloush avatar Apr 22 '25 20:04 miloush