Is it possible to use a setter to return a property to its default value?

自作多情 提交于 2019-12-01 04:21:07

It doesn't really work like that. The DependencyProperty system works by considering numerous different value sources. And as you can see here, style setters and style triggers are considered to be separate sources. (They're numbered 8 and 6 respectively in the "Dependency Property Setting Precedence List" section.) Whichever of the active value sources has the highest priority wins.

Property sources of one kind cannot remove the value provided by a different source. The only reason triggers are able to change the value from what a setter sets it to is that triggers have a higher priority. There's no power to eradicate a value supplied by a lower-priority source.

The way to achieve the particular goal you've expressed here would be to invert the sense of the trigger - don't define a style setter, and make the trigger active only when IsMouseOver is false. Of course, that won't help you in all the possible cases where you might want to do this. But since there isn't a general solution, I think you'd need to solve each specific problem in its own way.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!