Problem with DataTrigger binding - setters are not being called

Posted by aoven on Stack Overflow See other posts from Stack Overflow or by aoven
Published on 2010-03-24T12:31:08Z Indexed on 2010/03/24 12:33 UTC
Read the original article Hit count: 405

Filed under:
|
|
|

I have a Command bound to a Button in XAML. When executed, the command changes a property value on the underlying DataContext. I would like the button's Content to reflect the new value of the property.

This works*:

<Button Command="{x:Static Member=local:MyCommands.TestCommand}"
        Content="{Binding Path=TestProperty, Mode=OneWay}" />

But this doesn't:

<Button Command="{x:Static Member=local:MyCommands.TestCommand}">
  <Button.Style>
    <Style TargetType="{x:Type Button}">
      <Style.Triggers>
        <DataTrigger Binding="{Binding Path=TestProperty, Mode=OneWay}" Value="True">
          <DataTrigger.Setters>
            <Setter Property="Content" Value="Yes"/>
          </DataTrigger.Setters>
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=TestProperty, Mode=OneWay}" Value="False">
          <DataTrigger.Setters>
            <Setter Property="Content" Value="No"/>
          </DataTrigger.Setters>
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </Button.Style>
</Button>

Why is that?

* By "works" I mean the Content gets updated whenever I click the button.

TIA

© Stack Overflow or respective owner

Related posts about wpf

Related posts about xaml