Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional Tooltip Based On Checkbox WPF

I've got a checkbox and a button in my WPF MVVM app. If the checkbox is checked I want a tooltip on the button that says "x" and if it's unchecked the tooltip should say "y".

Anyone know the best way to do this? I think it could be done with a separate property in my view model, but maybe there's an easier way to do this in just the xaml?

Thanks in advance.

like image 760
m4gik Avatar asked Jul 08 '26 14:07

m4gik


1 Answers

You could use a Style with a DataTrigger that binds to the IsChecked property of the CheckBox:

<CheckBox x:Name="chk" Content="CheckBox" />
<Button Content="Button">
    <Button.Style>
        <Style TargetType="Button">
            <Setter Property="ToolTip" Value="y" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsChecked, ElementName=chk}" Value="True">
                    <Setter Property="ToolTip" Value="x" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>
like image 105
mm8 Avatar answered Jul 10 '26 06:07

mm8