There is a server, it has a Solve button (solve the problem). I want to make its IsEnabled property dependent on two public properties of the form (which I set myself), but one of the properties would have priority. If IsRunning (server running) is set to true, then Solve.IsEnabled == true and vice versa. (this property is in priority) But at the same time, if the Processing property (the problem is in the process of solving) is true, then Solve.IsEnabled == false (so that you cannot start solving another task until the previous one has been solved) and vice versa. I tried to make a direct dependency on IsRunning by binding, and inverse from Processing through a data trigger, but then the binding takes over the entire priority, as it were, and the trigger already has no effect on anything. And if I try to set both dependencies with triggers, then only the last specified trigger is affected.

<Button Content="Solve" Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="9" Click="btSolve_Click"> <Button.Style> <Style TargetType="Button"> <Style.Triggers> <DataTrigger Binding="{Binding Path=IsRunning, Mode=OneWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" Value="True"> <Setter Property="IsEnabled" Value="True"/> </DataTrigger> <DataTrigger Binding="{Binding Path=IsRunning, Mode=OneWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" Value="False"> <Setter Property="IsEnabled" Value="False"/> </DataTrigger> <DataTrigger Binding="{Binding Path=Processing, Mode=OneWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" Value="False"> <Setter Property="IsEnabled" Value="True"/> </DataTrigger> <DataTrigger Binding="{Binding Path=Processing, Mode=OneWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" Value="True"> <Setter Property="IsEnabled" Value="False"/> </DataTrigger> </Style.Triggers> </Style> </Button.Style> </Button> 
  • You can add the CanSolve property, the logic to which you have already described in the question. - Monk
  • @Monk aha yeah, I’ve just reached it myself. - PECHAPTER

1 answer 1

The only way I found to do this:

 public bool btSolveIsEnabled { get { return IsRunning && !Processing; } } 

And come in direct relation.

  • It is worth noting that if this is WPF, then now the change of the IsRunning and Processing properties should also notify the change of btSolveIsEnabled . - Monk
  • @Monk I know, but I use Fody.PropertyChanged for this, so I don’t need to bother about it. :) - PECHAIRTER