microsoft/winforms-designer-extensibility

Simple Test Form does not work

alprinias opened this issue · 2 comments

Hi,
following the blog post https://devblogs.microsoft.com/dotnet/winforms-cross-platform-dotnet-maui-command-binding
I downloaded the MauiEidt solution and tried the SimpleTestForm in the MauiEdit.WinForms project (by uncommenting the lines
Application.Run(new SimpleTestForm());
return;
in the Main method of the Program.cs file). The program runs, the form shows up, but nothing happens when I check/uncheck the chackbox, which is supposed the toggle the command availability. I.e. the button never gets enabled and when I set breakpoints in the SampleCommandAvailability property setter (of the SimpleCommandViewModel), they are never hit. (edit: They are only hit after I stop debugging.)

Any idea what might be wrong?

Don't know whether this is related, but the all items in the toolbox are greyed out. (edit: forget about this, after a Visual Studio Repair, toolbox behaves as expected.)

All this with Visual Studio 2022 Community 17.5.4

Thanks and regards,
Alex

To answer my own question, the Binding of the CommandAvailability viewmodel property to the "Checked" property of the Form was defined as
_commandAvailabilityCheckBox.DataBindings.Add(new Binding("Checked", simpleCommandViewModelBindingSource, "SampleCommandAvailability", true));
and not as
_commandAvailabilityCheckBox.DataBindings.Add(new Binding("Checked", simpleCommandViewModelBindingSource, "SampleCommandAvailability", true, DataSourceUpdateMode.OnPropertyChanged));

When the last parameter was added (either in the SimpleForm.Designer.cs or through the visual Binding UI), it works.

If no DataSourceUpdateMode is specified, the default OnValidation is implied. Control validation is triggered when the control (checkbox) loses focus. However, it this case, there is no other control on the form to take the focus and Validation is never triggered for the checkbox. This is why OnPropertyChanged never happens, but only when the Form is closed (and the program exits).

Alex

Sorry for the oversight, thanks for fixing it!