4 ms·
One I've come across is binding a command to a button. With anonymous inner classes you can have something like: myButton.AddListener(new Command { bool
by flukus 10y ago
One I've come across is binding a command to a button. With anonymous inner classes you can have something like:
myButton.AddListener(new Command {
bool enabled() {
return false; //more logic goes here
}
void onClick() {
//do something
}
});
- voltagex_ 10y agoI'm not convinced that gives you that much more over using a delegate.
- flukus 10y agoIt doesn't. It's a nice to have feature, not a world changing one.
- ygra 10y agoBut that's something that's very rare in C#. Usually for that sort of thing you have events and delegates. Although I have to admit that the library I work on had a few patterns that would benefit from anonymous interface implementations, but not that much to really miss the feature.
- tigershark 10y agomuch much better to use DelegateCommand: SubmitCommand = new DelegateCommand(()=> DoSomething(), ()=> IsSubmitEnabled); Edit: and obviously the Command DependencyProperty on the Button will be bound to the SubmitCommand property, instead of accessing directly the button from the ViewModel, that is the worst possible thing that you can possibly do.