任何人都可以提供一些建议,说明如何在Silverlight中实现一个控件,该控件显示的图像缩略图在悬停时放大到更大尺寸?在悬停上放大图像缩略图
4
A
回答
2
我做了一个类似的按钮。这里是代码 - 我相信你可以很容易地适应它来改变图像。请注意,我从未真正发布过这个代码;当我学习Silverlight时,这只是一个实验。不要把它当成最佳实践的例子。
XAML:
<UserControl x:Class="GrowingButton.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.Resources>
<Storyboard x:Name="growStoryboard">
<DoubleAnimation
Storyboard.TargetProperty="Width"
Storyboard.TargetName="testButton"
Duration="0:0:0.1"
By="20">
</DoubleAnimation>
<DoubleAnimation
Storyboard.TargetProperty="Height"
Storyboard.TargetName="testButton"
Duration="0:0:1"
By="-20">
</DoubleAnimation>
</Storyboard>
<Storyboard x:Name="shrinkStoryboard">
<DoubleAnimation
Storyboard.TargetProperty="Width"
Storyboard.TargetName="testButton"
Duration="0:0:1"
By="-20">
</DoubleAnimation>
<DoubleAnimation
Storyboard.TargetProperty="Height"
Storyboard.TargetName="testButton"
Duration="0:0:0.1"
By="20">
</DoubleAnimation>
</Storyboard>
</Grid.Resources>
<Button x:Name="testButton" Content="Test" Grid.Column="1" MouseEnter="Button_MouseEnter" MouseLeave="Button_MouseLeave" VerticalAlignment="Center" HorizontalAlignment="Center" Width="50" Height="50">
</Button>
</Grid>
</UserControl>
代码:
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
private void Button_MouseEnter(object sender, MouseEventArgs e)
{
this.shrinkStoryboard.SkipToFill();
this.growStoryboard.Begin();
}
private void Button_MouseLeave(object sender, MouseEventArgs e)
{
this.growStoryboard.SkipToFill();
this.shrinkStoryboard.Begin();
}
}
1
只要您的控件具有用于MouseOver状态的VisualState,就可以使用DoubleAnimation
(或DoubleAnimationUsingKeyframes
)在控件上执行ScaleTransform。
为您的缩略图/图像控件创建不同的VisualState(位于VisualStateGroup内)将为您省去将代码连接到代码后面的麻烦。您还可以在Blend中直观地定义不同的缩放比例,这是一个很好的功能。
0
本页面 - Fish Eye Menu有做类似于你想要什么东西的例子。由于某些原因,尽管我安装了Silverlight,但它并未显示Silverlight版本。这可能是与它在Silverlight 2中。
相关问题
- 1. 悬停缩略图播放
- 2. 图像缩放悬停放大容器
- 3. fotorama在缩略图中悬停图像
- 4. 在悬停上放大图像
- 5. 纯CSS悬停改变大的图像在缩略图
- 6. CSS放大悬停图像
- 7. 在缩略图的悬停上显示大图
- 8. 如何在缩略图悬停上显示图像预览
- 9. 在悬停缩略图上切换图像?
- 10. 在悬停缩略图上用jquery更改主图像
- 11. 图片缩略图悬停缩放图片
- 12. 将鼠标悬停在缩略图图像上并用透明放大镜图像覆盖
- 13. 在鼠标悬停时放大图像
- 14. 悬停时CSS缩放图像
- 15. 悬停时的图像缩放
- 16. 悬停时的图像缩放效果
- 17. 悬停/缩放变换背景图像
- 18. 放大悬停图像重叠问题(CSS变换:缩放)
- 19. 图像缩放/成长在缩略图
- 20. 图像悬停像谷歌图像缩放
- 21. 图像放大镜 - 放大图像悬停和平移图像鼠标移动
- 22. 小图像在大图像悬停css
- 23. 使用变换缩放悬停上的图像:缩放,仍然使图像变大
- 24. 的CSS缩略图悬停在WordPress
- 25. 位置放大图像悬停
- 26. 将鼠标悬停时放大图像
- 27. 图像放大悬停与链接
- 28. 在缩略图按钮上的鼠标悬停事件上应用图像?
- 29. 将鼠标悬停在缩放图像上
- 30. 在容器悬停上缩放背景图像
嗨,我想要做类似的事情,如果我有多个图像,我只是在Storyboard.TargetName =“testButton”中添加名称 – GJJ 2011-05-23 04:39:39