You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

绑定Command后Button的IsMouseOver触发器失效问题排查

按钮样式悬停失效问题

更新

我已找到问题所在。Command处于不可执行状态,因此Button实际上处于禁用状态,该问题与myStyle无关。

预期行为

为Button定义了如下样式,当鼠标悬停在按钮上时,opacity会从0.65变为1。

样式代码

<Style x:Key="myStyle" TargetType="Button">
    <Setter Property="Opacity" Value="0.65" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Grid>
                    <Grid.Background>
                        <ImageBrush ImageSource="{StaticResource SomeImage}" />
                    </Grid.Background>
                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Triggers>
         <Trigger Property="IsMouseOver" Value="True">
             <Setter Property="Opacity" Value="1" />
         </Trigger>
    </Style.Triggers>
</Style>

该样式原本可正常工作:鼠标悬停时Button的opacity从0.65变为1,但当按如下方式绑定Command属性后出现异常:

按钮绑定代码

<Button Command="{Binding SelectScenarioCommand}"
        Style="{DynamicResource myStyle}">
</Button>

实际行为

绑定Command后,鼠标悬停在按钮上时,opacity值保持不变(始终为0.65)。


内容的提问来源于stack exchange,提问作者Nowayout

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 16:06:02