开发者

wpf mvvm equality

开发者 https://www.devze.com 2022-12-09 19:28 出处:网络
I would like to use an MVVM in a WPF project I\'m working on, including the use of RelayCommands (aka DelegateCommands). I\'m running into an interesting but frustration problem in implementing equali

I would like to use an MVVM in a WPF project I'm working on, including the use of RelayCommands (aka DelegateCommands). I'm running into an interesting but frustration problem in implementing equality for my ViewModels, outlined here. I have a base class in my ViewModel h开发者_开发问答ierarchy which examines all properties reflectively as part of its equality comparison, and the Command consistently fails even when it looks like it shouldn't.

How are others of you using this design approach dealing with equality?

Cheers,

Berryl


If you are comparing delegates, it's likely that, especially if you use lambdas or anonymous delegates, that their RuntimeTypes are different.

My suggestion would be that you override the Equals method for these types manually on each type. You are likely taking a performance hit in doing these reflection-based comparisons and you are always going to run into these little nitpicky problems.

I know it feels like something you should be able to solve once and forever, but this doesn't seem likely. I hope this doesn't let the wind out of your sails too much.

0

精彩评论

暂无评论...
验证码 换一张
取 消