tags:

views:

204

answers:

1

I have a custom control that needs a minor adjustment when running on XP or Vista with the Aero theme, is there a simple way to detect the theme (operating system detection isn't enough because the user can change the theme) and use this in a style trigger?

I need to apply a small margin change on Vista to get the look required:

        <Setter Property="Margin"
                Value="0,-1,0,-1" />

The above setter is currently unconditional (e.g. not in a Trigger) but requires me having two versions.

Ideally the solution should be Xaml only, but if necessary I could expose a property to associate to a DataTrigger.

+1  A: 

You could write a ValueConverter that takes the margin settings and does a platform/theme check in its Convert method.

Sean
I had considered that, but I thought that it is moving designer logic into the backend, whilst detecting the Theme in the Xaml (or projecting it into there) leaves the Xaml responsible for the visual appearance.
Ray Hayes
@Sean : a converter is useful with a binding, but in that case there's no binding. A markup extension would probably be more adequate. @Ray : a converter or a markup extension are not "backend"... they're just boilerplate code to make your front-end work. If you always do absolutely everything in XAML, you won't achieve much ;)
Thomas Levesque
@Thomas, I'm aware that I can't do everything from XAML, but I want the code behind to expose general information, not make decisions on presentation. Having reread @Sean's answer it seems I missed part of his point (slaps forehead). What I actually did in the end was expose a generic settings MVVM which includes a "CurrentTheme" property and therefore allows me to detect "Luna" or "Aero" themes.
Ray Hayes