任何人都可以提供一些建議,說明如何在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