I'm wondering how to bind a color property of an element to the ViewModel without leaking the view implementation (e.g. WPF) into the ViewModel and thus creating a dependency. For example, I have a TextBlock
and I've bound its Foreground
property like this:
<TextBlock Name="MyTextBlock" Foreground="{Binding Path=PropName}" />
Many sources like this, this, this, etc. use System.Windows.Media.Brush
from within the ViewModel, like this:
public System.Windows.Media.Brush PropName
{
get
{
//assume presentation logic to determine correct color.
return System.Windows.Media.Brushes.Red;
}
}
I don't want my ViewModel to be tied to WPF (i.e. via System.Windows.Media.Brush
) or any other presentation framework. Is there some way of doing it so that I can use a general or universal color type or even an RGB value and have it interpreted correctly in the XAML from the binding?