I am new to Xaml.
I am learning UWP (Universal Windows Platform) and I have more buttons, and I want to bind their Background property to the ViewModel property, which will change during some events.
I implemented INotifyPropertyChanged and everything works fine (the color of the buttons changes) when I bind the Background property in the button declaration in XAML:
<Button Content="0" Grid.Column="0" Grid.Row="5"
Background="{Binding ButtonColor, Source={StaticResource AppViewModel}}" Style="{StaticResource BasicButton}"/>
StaticResource AppViewModel is a resource in App.xaml:
<Application.Resources>
<viewModel:AppViewModel x:Key="AppViewModel" />
</Application.Resources>
I don’t know how good it is to declare a ViewModel for App.xaml, but this is the solution I found for global variables (variables are stored inside viewModel).
Now back to my question: Since I do not want to bind Background on each individual button, I tried to add it in a style similar to this:
<Style x:Key="BasicButton" TargetType="Button">
<Setter Property="Background" Value="{Binding ButtonColor, Source={StaticResource AppViewModel}}" />
</Style>
, , .
, .
?
.