Home > OS >  Data Trigger Based on Element Activity WPF
Data Trigger Based on Element Activity WPF

Time:07-19

I've got a button that is only conditionally enabled. I'd like to change the button's tooltip if the button is enabled or disabled.

<Button Name="OkButton" VerticalAlignment="Center" Command="{Binding Path=OkCommand}" 
                    CommandParameter="{Binding}" Click="OkButtonClick" Content="OK">
                <Button.Style>
                    <Style TargetType="{x:Type Button}">
                        <Setter Property="ToolTipService.ShowOnDisabled" Value="True" />
                        <Setter Property="ToolTip" Value="OK" />
                        <Style.Triggers>
                            <DataTrigger ***SomeCondition*** Value="False">
                                <Setter Property="ToolTip" Value="OK Disabled" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style> 
</Button>

I know that I can probably bind to some property in my view model, but I would like to know if there's a way to handle this all in XAML.

I've tried a lot of googling, but so far haven't found much of an answer at all.

Thanks!

CodePudding user response:

it can be Trigger, not DataTrigger:

<Trigger Property="IsEnabled" Value="False">
    <Setter Property="ToolTip" Value="OK Disabled" />
</Trigger>
  • Related