public static Color BrushToColor(Brush brush) { var solidBrush = brush as SolidColorBrush; if (solidBrush == null) { var gradientBrush = brush as GradientBrush; if (gradientBrush == null) { return(Colors.Transparent); } var collection = (GradientStopCollection)gradientBrush.SafeGetValue(GradientBrush.GradientStopsProperty); if (collection != null) { GradientStop gs = collection.SafeGetAt(collection.SafeGetCount() - 1); if (gs != null) { return((Color)gs.SafeGetValue(GradientStop.ColorProperty)); } } } return((Color)solidBrush.SafeGetValue(SolidColorBrush.ColorProperty)); }