Search code examples
c#wpfcustom-controlsskin

WPF properties and x:Null etc


I am using WPF as an example. Suppose that we have a contol X ,and we set its background to an image. Then we want on mouseover to have no background image. This can be achieved with x:Null . However if we dont specify x:Null it keeps the same image.

I am trying to create a custom skin engine for a platfrom that doesnt support WPF. I am trying to figure out how to reproduce this behaviour. The problem is that if i have a class XControlStyle and two instances of this class one for normal state and one for mouseover then it isnt obvious how to achieve what i did in wpf..

Because setting for example mouseover.Backgroundimage = null it cant tell whether user set it to null or it is null by default.. This problem is worse with value types.. Setting all the properties twice isnt an elegant solution.. Also i need a solution in order to make BackgroundImage like it was never set.I figured out 3 solutions (by properties,dictionary class for storing,wrapping properties values in a class wrapper) but although i implemented the last i am not satisfied.
Reading MSDN documentation to be inspired i think that they store these data as metadata somehow? So i am wondering whether metadata is a solution somehow for my problem.. Any idea?


Solution

  • These things are done via dependency property value precedence, there is a value lookup system and of the values that are found the one with the highest precedence is chosen. Dependency properties themselves are like dictionaries and there are several of those at various layers, e.g. the element themselves and styles. This system is very complex and i would claim that reproducing it is a huge project of its own.