110,535
社区成员
发帖
与我相关
我的任务
分享
<Image.Triggers>
<Trigger Property="Image.IsMouseOver" Value="true">
<Setter TargetName="imageOneKey" Property="Source" Value="/PunchControl;component/Resources/onekey_.png"></Setter>
</Trigger>
</Image.Triggers>
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.Resources>
<!--替换背景img-->
<BitmapImage x:Key="MyImageSource" UriSource="替换按钮.png" />
<!--Image Style-->
<Style x:Key="ImageStyle1" TargetType="{x:Type Image}">
<Setter Property="FlowDirection" Value="LeftToRight"/>
<!--原背景img-->
<Setter Property="Source" Value="按钮.png"/>
<Setter Property="OpacityMask" Value="{x:Null}"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Source" Value="{StaticResource MyImageSource}"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Image x:Name="img" Style="{StaticResource ImageStyle1}" Width="100" Height="200"></Image>
</Grid>
</Window>
[/quote]
谢谢,和3楼是一个意思。我就是有个疑问,这个Source属性必须在Style里设置,然后在Style里用触发器才可以吗?如果是直接设置了一个默认图片,然后直接像主楼那样用了触发器是不可以的吗?
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.Resources>
<!--替换背景img-->
<BitmapImage x:Key="MyImageSource" UriSource="替换按钮.png" />
<!--Image Style-->
<Style x:Key="ImageStyle1" TargetType="{x:Type Image}">
<Setter Property="FlowDirection" Value="LeftToRight"/>
<!--原背景img-->
<Setter Property="Source" Value="按钮.png"/>
<Setter Property="OpacityMask" Value="{x:Null}"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Source" Value="{StaticResource MyImageSource}"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Image x:Name="img" Style="{StaticResource ImageStyle1}" Width="100" Height="200"></Image>
</Grid>
</Window>