private static void ChangeAllWindowButtonCommandsBrush(this MetroWindow window, IBrush brush, Position position = Position.Top) { // set the theme to light by default if (position == Position.Right || position == Position.Top) { // set the theme based on color lightness var theme = brush.NeedLightTheme() ? WindowCommandTheme.Light : WindowCommandTheme.Dark; window.WindowButtonCommands?.SetValue(WindowButtonCommands.ThemeProperty, theme); // clear or set the foreground property if (brush != null) { window.WindowButtonCommands?.SetValue(TemplatedControl.ForegroundProperty, brush); } else { window.WindowButtonCommands?.ClearValue(TemplatedControl.ForegroundProperty); } } }