GorillaApe
GorillaApe

Reputation: 3641

Button and datatrigger doesn't work

I want to make a button with this trigger.However this doesn't work .Even custom datatemplte doesn't. This fails with

{"Triggers collection members must be of type EventTrigger."}

<Button cal:Message.Attach="Switch"  Width="55" HorizontalAlignment="Left" 
        Style="{StaticResource OrderProductButton}"  Margin="6,4,0,7">

    <StackPanel Orientation="Horizontal">
        <TextBlock x:Name="literal" Foreground="White" 
                   xml:space="preserve">€</TextBlock>
        <TextBlock Foreground="White"  xml:space="preserve"> / </TextBlock>
        <TextBlock x:Name="percent" Foreground="Gray"> %</TextBlock>
    </StackPanel>

    <Button.Triggers>
        <DataTrigger Binding="{Binding IsPercent}" Value="True">
            <Setter Property="TextBlock.FontWeight" Value="Bold" 
                    TargetName="percent"  />
            <Setter Property="TextBlock.Foreground" Value="White" 
                    TargetName="percent"  />
        </DataTrigger>
        <DataTrigger Binding="{Binding IsPercent}" Value="false">
            <Setter Property="TextBlock.FontWeight" Value="Bold" 
                    TargetName="literal"  />
            <Setter Property="TextBlock.Foreground" Value="White" 
                    TargetName="literal"  />
        </DataTrigger>
    </Button.Triggers>
</Button>

Upvotes: 2

Views: 276

Answers (1)

Zebi
Zebi

Reputation: 8882

Does using a style work for you?

<Style TargetType="Button"> <!-- use a key if you want to target only specific buttons -->
  <Style.Triggers>
    <DataTrigger Binding="{Binding IsPercent}" Value="True">
        <Setter Property="TextBlock.FontWeight" Value="Bold" 
                TargetName="percent"  />
        <Setter Property="TextBlock.Foreground" Value="White" 
                TargetName="percent"  />
    </DataTrigger>
    <DataTrigger Binding="{Binding IsPercent}" Value="false">
        <Setter Property="TextBlock.FontWeight" Value="Bold" 
                TargetName="literal"  />
        <Setter Property="TextBlock.Foreground" Value="White" 
                TargetName="literal"  />
    </DataTrigger>
  </Style.Triggers>
</Style>

Upvotes: 1

Related Questions