I have a button in which I want to set the backgroud. For that, I am using a data trigger to check a property in my view model. I want that the change in this property run the trigger. However, I need also the value of another property of the button, but I don't know that trigger will run if this property changes, only I want to run the trigger when changes the property on my viw model.
My axml is this:
<Style x:Key="btnComponentesBuscarCustomTemplate" TargetType="{x:Type Button}"><Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/><Setter Property="Background" Value="{StaticResource Button.Static.Background}"/><Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}"/><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/><Setter Property="BorderThickness" Value="1"/><Setter Property="HorizontalContentAlignment" Value="Center"/><Setter Property="VerticalContentAlignment" Value="Center"/><Setter Property="Padding" Value="1"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type Button}"><Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true"><ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/></Border><ControlTemplate.Triggers><MultiDataTrigger><MultiDataTrigger.Conditions><Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}" Value="true"/><Condition Binding="{Binding ElementName=ucPrincipal, Path=DataContext.BuscarEstado}" Value="0"/></MultiDataTrigger.Conditions><Setter Property="Background" Value="{DynamicResource BotonEnabled}"/><Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Static.Border}"/></MultiDataTrigger><MultiDataTrigger><MultiDataTrigger.Conditions><Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}" Value="true"/><Condition Binding="{Binding ElementName=ucPrincipal, Path=DataContext.BuscarEstado}" Value="1"/></MultiDataTrigger.Conditions><Setter Property="Background" Value="{DynamicResource BotonOcupado}"/><Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Static.Border}"/></MultiDataTrigger><MultiDataTrigger><MultiDataTrigger.Conditions><Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}" Value="true"/><Condition Binding="{Binding ElementName=ucPrincipal, Path=DataContext.BuscarEstado}" Value="2"/></MultiDataTrigger.Conditions><Setter Property="Background" Value="{DynamicResource BotonFinalizacionCorrecta}"/><Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Static.Border}"/></MultiDataTrigger><MultiDataTrigger><MultiDataTrigger.Conditions><Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}" Value="true"/><Condition Binding="{Binding ElementName=ucPrincipal, Path=DataContext.BuscarEstado}" Value="3"/></MultiDataTrigger.Conditions><Setter Property="Background" Value="{DynamicResource BotonFinalizacionincorrecta}"/><Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Static.Border}"/></MultiDataTrigger><MultiDataTrigger><MultiDataTrigger.Conditions><Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}" Value="false"/><Condition Binding="{Binding ElementName=ucPrincipal, Path=DataContext.BuscarEstado}" Value="0"/></MultiDataTrigger.Conditions><Setter Property="Background" Value="{DynamicResource BotonDisabled}"/><Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Static.Border}"/><Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/></MultiDataTrigger><MultiDataTrigger><MultiDataTrigger.Conditions><Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}" Value="false"/><Condition Binding="{Binding ElementName=ucPrincipal, Path=DataContext.BuscarEstado}" Value="1"/></MultiDataTrigger.Conditions><Setter Property="Background" Value="{DynamicResource BotonOcupado}"/><Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Static.Border}"/><Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/></MultiDataTrigger><MultiDataTrigger><MultiDataTrigger.Conditions><Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}" Value="false"/><Condition Binding="{Binding ElementName=ucPrincipal, Path=DataContext.BuscarEstado}" Value="2"/></MultiDataTrigger.Conditions><Setter Property="Background" Value="{DynamicResource BotonFinalizacionCorrecta}"/><Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Static.Border}"/><Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/></MultiDataTrigger><MultiDataTrigger><MultiDataTrigger.Conditions><Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}" Value="false"/><Condition Binding="{Binding ElementName=ucPrincipal, Path=DataContext.BuscarEstado}" Value="3"/></MultiDataTrigger.Conditions><Setter Property="Background" Value="{DynamicResource BotonFinalizacionincorrecta}"/><Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Static.Border}"/><Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/></MultiDataTrigger>
"BuscarEstado" is my property in my view model and the color depends on if the button is enabled or not. But I only want to run the trigger when "BuscarEstado" is changed. I want this because in this way I only run the converter once, becuase in my view model I set the "IsEnabled" and the "BuscarEstado" but they are related properties, so I don't want to run twice the converter.
When I use a multi value converter I use the properties as parameters, but in the case of data triggers the trigger is run when any of the conditions change.
I would like to use a multi data trigger because is more efficient that a multi value converter, so I prefer to use the multi data trigger, but if the multi data trigger it will be run twice then I am not sure if it is better to use the multidata trigger or the multi value converter.
So how can run the multi value converter when BuscarEstado is changed and set the background property according with the values of BuscarEstado and IsEnabled.
Thank so much.