Styling WECPOF applications and ViewModels
This post is about how to get the cool things of WPF to merge with the cool things of ECO.
We need to get the XAML styles into our declarative application
We need to declare and use style names on specific places in our UI where it makes sense to us.
We need to inject FormatStrings into our declarative DataBindings.
We need all of this at a granular level so that we will not be limited by the tool; for example we need to be able to control a single column in a grid separately, and also control its header differently than its cells.
All of this is done with XAML ResourceDictionaries. You can do your own with blend or notepad or any tool you like.
If you add your dictionaries to the Config folder of ECO, we will pick them up in the style Menu:
When you click a Style in WECPOF-runtime we load that Dictionary and merge it with the Application.
What can you change?
What can you do more?
When you set the StyleRef on ViewModelColumns you can define a corresponding Style in XAML.
Since the ViewModelColumn often spawns two controls; the TextBlock and in this case a TextBox we have defined the naming convention of STYLENAME.COMPONENTTYPE.
This enables you to define Style1 for all control types you use:
There is more
In WPF you can set a StringFormat on a Binding to aid in common transformations like “show only 2 decimals”, “present the DateTime in text format”, “This value is really percent” etc.
This need too is addressed with a naming convention in the XAML resource dictionary:
You use a StyleRef in the ViewModelColumn, and create a string entry in the resource dictionary with a key of STYLENAME.StringFormat. We apply this when setting up the Binding for the components in your view.
And we need Grid precision too
A DataGrid has Styles that apply to the whole Grid, but also you can apply individual styles per GridColumn:
And the result
The result is that you can be very flexible in how you want to convey information:
Help us out please!
Create your own styles and send them to us. We will use your name on the style so you will be a famous XAML designer before you know it!