在ControlTemplate中更改图像OnMouseOver

时间:2010-02-05 00:55:56

标签: wpf image triggers mouseevent controltemplate

这是我的XAML:

<Style x:Key="ExpanderStyle" TargetType="{x:Type ToggleButton}">
    <Setter Property="IsEnabled" Value="True" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <Image Source="/Images/SHCalendarLeftArrow.tiff" />
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

那么如何向Trigger OnMouseOver中的ControlTemplate图片添加{{1}}更改为不同的图片。

1 个答案:

答案 0 :(得分:3)

尝试在模板中使用Trigger

<Setter Property="Template"> 
    <Setter.Value> 
        <ControlTemplate> 
            <Image x:Name="PART_img" Source="/Images/SHCalendarLeftArrow.tiff" /> 

            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter TargetName="PART_img"
                            Property="Source"
                            Value="/Images/SomeOtherImage.tiff" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate> 
    </Setter.Value> 
</Setter>