I was experimenting using Powershell to load my WPF prototypes, and faced the same situation, so far I found that the solution is very simple it consists of adding interface methods to the powershell class, the last thing to deal with was the CanExecuteChanged event, through the exception message it says the method add_CanExecuteChanged wasnt found, and the solution is simply to add both the event adder and remover, for e
class Relay: System.Windows.Input.ICommand {
[Action[object]]$command;
Relay([Action[object]]$Command){
$this.command = $Command;
}
[void]add_CanExecuteChanged ([System.EventHandler]$handler){}
[void]remove_CanExecuteChanged ([System.EventHandler]$handler){}
[bool]CanExecute([object]$arg) {return $true; }
[void]Execute ([object]$arg){ $this.command?.Invoke($arg); }
}
for the INotifyPropertyChanged the situation is different since it needs getters and setters, and a call to the PropertyChanged handler on setters, the properties in powershell can be implmented as fields in C# and behind the scenes powershell add get_* and set_, which is the case in the dotnet when adding properties in the ggenerated IL you found get_, set_* methods which represents the getters and setters, for example:
class Demo {
[string]$MyProperty;
}
if you do a Get-Member -Force on an instance in the result you will find (get_MyProperty, set_MyProperty) methods, but when I tried to do so "for example like in java" the methods wont execute, but however I tried the binding without these methods and it works fine, here is my gist of the experiment, with bindings working in two way mode:
https://gist.github.com/mouadcherkaoui/7b0f32d9dbefa71102acdbb07299c9bb
and here is the source I modified, the repos it self contains a lot of good scripts:
https://github.com/SammyKrosoft/PowerShell/blob/master/How-To-Load-WPF-From-XAML.ps1
Best Regards.