Ответ 1
Использование триггеров:
<Button>
<Button.Style>
<Style TargetType="Button">
<!-- Set the default value here (if any)
if you set it directly on the button that will override the trigger -->
<Setter Property="Background" Value="LightGreen" />
<Style.Triggers>
<DataTrigger Binding="{Binding SomeConditionalProperty}"
Value="True">
<Setter Property="Background" Value="Pink" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
В MVVM вы также можете часто обрабатывать это в модели представления через свойства только для получения, например,
public bool SomeConditionalProperty
{
get { /*...*/ }
set
{
//...
OnPropertyChanged(nameof(SomeConditionalProperty));
//Because Background is dependent on this property.
OnPropertyChanged(nameof(Background));
}
}
public Brush Background =>
SomeConditinalProperty ? Brushes.Pink : Brushes.LightGreen;
Тогда вы просто привязываетесь к Background
.