You can do without the code-behind, almost.
You need to make the attached property, the value of which will be set through the EventTrigger, in your case when you click the left mouse button.
And next to MultiTrigger, which will work, subject to the presence of a value in the above-mentioned property.
UPD: code.
Model:
public class Model : INotifyPropertyChanged { private bool _isPropertySet; public event PropertyChangedEventHandler PropertyChanged; [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public Model() { SetPropertyCommand = new DelegateCommand(o => { IsPropertySet = !IsPropertySet; }); } public bool IsPropertySet { get { return _isPropertySet; } set { _isPropertySet = value; OnPropertyChanged(nameof(IsPropertySet)); } } public ICommand SetPropertyCommand { get; set; }
View:
<Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp1" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Window.DataContext> <local:Model /> </Window.DataContext> <Window.Resources> <ResourceDictionary> <Style TargetType="StackPanel"> <Style.Triggers> <MultiDataTrigger> <MultiDataTrigger.Setters> <Setter Property="Opacity" Value="0.1" /> </MultiDataTrigger.Setters> <MultiDataTrigger.Conditions> <Condition Binding="{Binding DataContext.IsPropertySet, RelativeSource={RelativeSource Self}}" Value="False" /> </MultiDataTrigger.Conditions> </MultiDataTrigger> </Style.Triggers> </Style> </ResourceDictionary> </Window.Resources> <Grid> <StackPanel Width="80" Height="80" Background="Red"> <i:Interaction.Triggers> <i:EventTrigger EventName="MouseLeftButtonDown"> <i:InvokeCommandAction Command="{Binding SetPropertyCommand}" /> </i:EventTrigger> </i:Interaction.Triggers> </StackPanel> </Grid>
You need one trigger per event to set the property, and one trigger that binds to this property and sets the desired Opacity value.