0

In xaml I have :

<UserControl.Resources>
        <Style x:Key = "TriggerStyle" TargetType = "Button">
            <Setter Property = "Foreground" Value = "Blue" />
            <Style.Triggers>
                <Trigger Property = "IsMouseOver" Value = "True">
                    <Setter Property = "Foreground" Value = "{Binding BackgroundColor, Mode=TwoWay}" />
                </Trigger>
            </Style.Triggers>
        </Style>
</UserControl.Resources>

 <Grid>
        <Button Width = "100" Height = "70" Style = "{StaticResource TriggerStyle}" Content = "Trigger"/>
</Grid>

Inthe view model I set the background color to green. In the viewModel I have:

private void GetBackgroundColor()
{
   return _brush = Brushes.Green;
}
public Brush BackgroundColor
{
    get
    {
       return _brush;
    }
    set
    {
       _brush = value;
       OnPropertyChanged("BackgroundColor");
    }
}

In the debug mode, the brush has the value, but on screen nothing happens. What I'm doing wrong?

Bogdan
  • 21
  • 4
  • 1
    You have a typo: `OnPropertyChanged("BackColor")` - property is called Back**ground**Color. – Sinatr Aug 14 '20 at 07:14
  • And that still won't work. Unless he's on win xp – Andy Aug 14 '20 at 07:23
  • From win 7 onwards. The button template has a rectangle in it which gives the default light blue background when you mouse over. In order to change the button background you need to change the template. Please see the link above. – Andy Aug 14 '20 at 07:27
  • And. Please google before asking questions.... or posting answers. – Andy Aug 14 '20 at 07:27

0 Answers0