2
我想用這個觸發器做一個按鈕。但是這不起作用。即使自定義數據不能。這種失敗按鈕和數據觸發器不起作用
{ 「Triggers集合成員必須是類型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>
您的觸發器集合是EventTrigger類型的成員,如錯誤消息所規定的那樣?我不是xaml專家,但它看起來像你使用DataTriggers而不是EventTriggers。 –
你有沒有試過用'RelativeSource'綁定? –