This project is read-only.

Question on applying styles

Jun 27, 2013 at 10:57 PM
This is probably a really stupid question, but I am not sure and hate guessing wrong.

1) Does it make any difference when creating views/models/controllers which order I do them in? If so, that may answer my next question...

2) When I try to list all the customers (or whatever) in my getAll result model, it doesn't show. I have the Text1, Text2, etc. set right. But I don't have a style defined to use them (say CustomerListStyle). In the sample code I have that works, that is defined in each attached theme. For example the battleship version is:

<Style x:Key="CustomerListStyle" TargetType="ListBox" BasedOn="{StaticResource Battleship-Control-ListBox}">
    <Setter Property="ItemTemplate" Value="{DynamicResource CODE.Framework-StandardTemplate-LargeText01}" />
So my question is this. If I create a view from scratch, do I have to create one of these for each theme, open the theme and paste it in? Or is there some generic ListStyle reference I could use that will get the correct version and apply it? And, if so, where do I get a list of the generic versions I can use (sort of like we do for the overall style as in Style="{DynamicResource CODE.Framework-Layout-SimpleFormLayout} ) ?

One last question - when I create a view I get a template that gives me lots of choices (themes, theme count, etc.). Where can I get a good description (link to docs, etc.) of the effects of those and how to know how I might set them?


Jun 28, 2013 at 12:59 PM
Creation order does not matter.

There is no standard listbox style, but you don't always need a style. You can simply define your listbox in the view like so:
<ListBox ItemsSource="{Binding MyCustomers}" ItemTemplate="{DynamicResource CODE.Framework-StandardTemplate-LargeText01}" />
So this will now show a listbox with the LargeText01 template applied, whatever that template may be for the theme you have chosen. In many cases, this may do the trick.

However, the advantage of creating a new style with that one property set and then referring to this style by name is that you have even more flexibility in different themes. For instance, in the Geek theme, your style may refer to LargeText01, while in the Metro theme, your style of the same name may refer to a completely different template (even a non-standard one if you were so inclined). So this is a nifty benefit to have and really helps with long term maintainability and protects your investment. So it is probably worth doing, I would think, and we always go that route in our apps.

Jun 28, 2013 at 6:40 PM

Is there a reference on working with the CODE FW styles? I have some information in general, but am looking for a little more - both the benefits that some provide (such as the list style that will list out the values named Text1, Text2, etc. or the Edit which will try to associate the label and textbox so they appear as appropriate for a given theme.

So not only the benefits of the various styles, but also information on ways to modify them, etc.

If I have a reference to a style in List.Geek.xaml, List.Default.xaml, and List.AllThemes.xaml - which one is used, assuming the theme is not set to Geek? Can we change the evaluation sequence?


Jun 28, 2013 at 8:02 PM
Edited Jun 29, 2013 at 3:54 AM
Ok, I have some answers (but not all):

For precedence, the default is used when no theme exists. If a theme exists, then it is used. If a Layout.xaml exists and has a key that is also in the theme specific dictionary, then the layout.xaml version is used. So I guess the style sequence is:

inline with the control
style key defined in the document
theme specific library.xaml
default.xaml (although it seems as if references to styles here are ignored - I need to do more research before I report this as a bug - it may be just me missing something else.....)

Not sure where the AllThemes.xaml fits.

For others reading this, here is a link supplied on this subject in another thread:

I still haven't figured out how to pass the column titles to the listbox (so it doesn't show Text1, etc.), but am working on that.


Jul 1, 2013 at 9:28 PM
Yeah, that article is a good source. This one may also be helpful: And maybe even this one:

For the columns: The default ones that show up are just that: Defaults. You can define your own columns as shown in this quick tip topic: So you can define that you want to use a specific standard template and then in addition define columns like shown in that article and then that will override the column specifics. You can do that in the view, or you can do it in a style so it becomes specific to a theme.

So the basic idea might be something like this: Define a listbox and bind its items source to data. Then, in the default resource dictionary specify a standard data template to be used, so if all else fails, it could always use that. And then, for the themes you want to explicitly support, either specify the use of a standard data template or create your own, and (if you want columns) specify the exact columns you want in addition. (Column definitions are picked up when the data template includes the use of our smart list data template... otherwise it is ignored... which means it is always safe to define the columns)