Enforce Design Guidelines With Styles And Behaviors
Often times, the design for an interface calls for guidelines that cannot be sufficiently controlled with styles in a Silverlight resource dictionary alone. Take for instance, the Windows Phone interface shown below, and imagine that the design guidelines specify that the application/page name (the red arrow is pointing to this element) is supposed to be in all caps. How do you enforce this in the interface in a painless manner?
One way, is to define a style for the inteface element and attach a behavior that forces the string to be in all caps. Attaching behaviors in styles is something that I just discovered was possible, and it's pretty amazing!
I've created a sample project that contains two very simple TextBlock styles and associated behaviors that either force TextBlock text to be upper case or lower case as appropriate. What's great about this is that people consuming the styles no longer have to worry about the case of the text. The style alone controls the text case. This is particularly interesting in situations where TextBlocks are bound to data as the form of the bound data may not be known (e.g. it may not be all upper case, mixed case, etc...). The image below is a screen shot of the sample application