gpt4 book ai didi

c# - 按钮和数据触发器不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 13:50:06 24 4
gpt4 key购买 nike

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

{"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>

最佳答案

使用样式对您有用吗?

<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>

关于c# - 按钮和数据触发器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13923587/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com