Creating a viewmodel to customize wpf button colors is a wrong approach. Button color scheme is something which belongs strictly to a view. Also many buttons means many view model instances, since each button might want to be unique - too much code for such a simple setting.
Button class doesn't have enough dependency properties to set color representing HoverColorBackground/HoverColorBorder/HoverColorForeground. Alternatives are to create a derived Button class (way to go when DP are of some complex type and/or have associated logic) or use attached properties. I have written a tip, which coveres the second approach.
short version
create an attached DP
public static class Alt
{
#region Background
public static readonly DependencyProperty BackgroundProperty =
DependencyProperty.RegisterAttached("Background", typeof(Brush),
typeof(Alt), new PropertyMetadata(null));
public static Brush GetBackground(DependencyObject obj)
{
return (Brush)obj.GetValue(Alt.BackgroundProperty);
}
public static void SetBackground(DependencyObject obj, Brush value)
{
obj.SetValue(Alt.BackgroundProperty, value);
}
#endregion
}
set custom value for that property
<Button Content="Blue" Foreground="White" Margin="5"
Background="Blue" ui:Alt.Background="DarkBlue"/>
make sure that template know how to use that property
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="ButtonGrid"
Property="Background"
Value="{Binding Path=(ui:Alt.Background),
RelativeSource={RelativeSource TemplatedParent}}"/>
</Trigger>
Works for any control. Many DP can be mixed in any combination.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…