Ray Hayes
Ray Hayes

Reputation: 15015

How to detect the current theme in WPF's Xaml?

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.

Upvotes: 1

Views: 965

Answers (1)

Sean
Sean

Reputation: 62472

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

Upvotes: 1

Related Questions