Im trying to change the background color of a stack layout when a button is pressed. This is the stack layout:
<StackLayout Padding="20" x:Name="LayoutTest" BackgroundColor="{Binding BackgroundTest}">
<Label Text="Background" TextColor="Black" FontSize="Subtitle" FontAttributes="Bold" VerticalOptions="Center"></Label>
<Frame CornerRadius="10" Padding="10" Margin="0, 0, 0, 10" BackgroundColor="#00A6FF">
<RadioButton GroupName="colors"></RadioButton>
</Frame>
<Frame CornerRadius="10" Padding="10" Margin="0, 0, 0, 10" BackgroundColor="#13CE66">
<RadioButton GroupName="colors" Command="{Binding ChangeBgColorGreen}"></RadioButton>
</Frame>
<Frame CornerRadius="10" Padding="10" Margin="0, 0, 0, 10" BackgroundColor="#FFD185">
<RadioButton GroupName="colors"></RadioButton>
</Frame>
<Frame CornerRadius="10" Padding="10" Margin="0, 0, 0, 10" BackgroundColor="#F95F62">
<RadioButton GroupName="colors"></RadioButton>
</Frame>
<Button Text="Change Color" Command="{Binding ChangeColor}"></Button>
</StackLayout>
And this is my view model:
class SettingsPageViewModel : BaseViewModel
{
public String BackgroundTest { get; set; }
public Command ChangeColor { get; }
public SettingsPageViewModel()
{
Title = "Dashboard ";
ChangeColor = new Command(ChangeBgColor);
}
void ChangeBgColor()
{
BackgroundTest = "#F95F62";
}
}
However, whenever the ChangeColor button is clicked, it does not seem to change the 'BackgroundTest' value. Im quite new to MVVM so am not sure how best to do this. Any help would be greatly appreciated.