2

我想用这个触发器制作一个按钮。但是这不起作用。即使自定义数据模板也没有。这失败了

{"触发器集合成员必须是 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">€&lt;/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>
4

1 回答 1

1

使用风格对你有用吗?

<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>
于 2012-12-17T23:04:07.477 回答