#225 – Using a Brush that Will Update When a System Color Changes

The System.Windows.SystemColors class contains a series of static properties that expose the current predefined system colors.  (Click here to see a list of these system colors).

If you use one of these predefined system colors as a brush using the x:Static markup extension, the color used will be the value of that system color at the time that the application started.  If the system color changes while the application is running, the brush will not change.

You can create and use a dynamic brush, which will change whenever the system color changes, as follows:

		<Ellipse Height="100" Width="200" Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" Margin="30"/>

Notice that we use the XxxBrushKey property, rather than the XxxBrush property.  Both properties give us a brush, but the XxxBrushKey property gives us a dynamic brush that will change when the system color changes.


About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: