user853710
user853710

Reputation: 1767

How to have the Button react on the Bindings Property Change change in WPF?

I have a control that has a DataContext being loaded and based on it I create a bunch of Buttons. I would like to have the Button react on a change to the bound objects change

<Button ToolTip="{Binding Tip}" 
        ib:ButtonProperties.Image="{Binding EnabledSource}" 
        ib:ButtonDProperties.Image="{Binding DisabledSource}" 
        Content="{Binding Text}" 
        IsEnabled="{Binding DefaultEnabled}"
        Tag="{Binding .}"

        Click="ToolBarButtonButton_Click"

        Style="{StaticResource ImageButton}">

</Button>

For simplification purposes, Lets say, I databind a collections of Custom objects which Have a Property called "IsPerfect" of type bool. The Object assigned to the button is set as the tag as well.

I would like to have the button reacting on the property "IsPerfect" that belongs to the databound object and then execute a eventhandler or enable/disable the button.

Upvotes: 0

Views: 208

Answers (2)

Colin
Colin

Reputation: 551

You can use a style to fulfill your goal.

<Button>
  <Button.Style>
   <Style>
      <DataTrigger Binding="{Binding IsPerfect}" Value="True">
         <Setter Property="Button.IsEnabled" Value="True"></Setter>
      </DataTrigger>
   </Style>
  <Button.Style>
</Button>

Upvotes: 0

Fede
Fede

Reputation: 44048

<Button IsEnabled="{Binding SomeBoolValue}"/>

Upvotes: 1

Related Questions