wpfxamldata-bindingdatatrigger

Data Trigger Based on Element Activity WPF


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.


Solution

  • it can be Trigger, not DataTrigger:

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