#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.