Blog Stats
  • Posts - 62
  • Articles - 11
  • Comments - 8
  • Trackbacks - 99

 

Coding with style

What if we could create CSS styles in C#?
Skinning would be soooo easy.
Think of the ZenGarden but in winForms.

public style Overdue
{
    fontname  = tahoma;
    fontsize  = 10px;
    forecolor = white;
    backcolor = red;
}

then, when applying the style to any object, if the object has the properties then it applies the value to the property, if not it just ignores it.

if (dueDate < today) textAmount.style = Overdue;

what do you think?


Feedback

# re: Coding with style

Gravatar Nice idea, but I'd prefer to use the standard CSS format for doing it. This way, you don't have to learn something new and you can reuse your skillz. Then again...

Style cssOverdue = Style.Load("styles.css", ".overdue");

Or, even...

StyleCollection colStyles = Style.Load("styles.css"); 1/18/2004 5:45 PM | Michael Flanakin

# re: Coding with style

Gravatar Good point Mike,

But as soon as the style is imported, it has to be interpreted by the language and at the end by the CLR.

So, even if the style is external (like a css file) or internally defined, the language has to have the functionality to understand it and use it.

That's why the 'style' keyword is needed.

The same would apply to VB.NET:

Style Overdue
FontName = Tahoma
FontSize = 10px
ForeColor = White
BackColor = Red
End Style

and all .NET languages as well

Would it be implemented in Orcas? 1/18/2004 7:30 PM | RebelGeekz

# re: Coding with style

Gravatar Unfortunately, XAML seems to be heading the other direction: toward HTML 3.0-like mixing of markup declaration and style.

You could implement this right now in C#/VB by using a Visitor-like pattern: come up with the style, then use the form "myStyle.applyTo(myControl)". As a separate object, styles could then be cloned from one another, inherited (populated up the chain through mybase construction), delegated, etc.--even more powerful than CSS. 2/10/2004 12:01 PM | Richard Tallent

Post a comment





 

Please add 5 and 2 and type the answer here:

 

 

Copyright © RebelGeekz