刚接触Silverlight,还不是很了解,就用土办法做了一个,效果: 鼠标放到文字连接上,显示一些悬停效果(用png图片),点击时,连接到某个页面.
1.MenuControl.xaml文件:
< UserControl x:Class = " DemoApp.MenuControl " xmlns= " http://schemas.microsoft.com/client/2007 " xmlns:x = " http://schemas.microsoft.com/winfx/2006/xaml " Width = " 400 " Height = " 300 " > < Grid x:Name = " LayoutRoot " Background = " White " > < Canvas Background = " #2595EB " > < Image x:Name = " img01 " Source = " bg.png " Canvas.Left = " 10 " Canvas.Top = " 120 " Width = " 80 " Height = " 25 " Visibility = " Collapsed " ></ Image > < Image x:Name = " img02 " Source = " bg.png " Canvas.Left = " 62 " Canvas.Top = " 120 " Width = " 100 " Height = " 25 " Visibility = " Collapsed " ></ Image > < TextBlock x:Name = " item01 " TextWrapping = " Wrap " MouseEnter = " item01_MouseEnter " MouseLeave = " item01_MouseLeave " MouseLeftButtonUp = " item01_MouseLeftButtonUp " Canvas.Left = " 30 " Canvas.Top = " 120 " Text = " Index " ></ TextBlock > < TextBlock x:Name = " item02 " TextWrapping = " Wrap " MouseEnter = " item02_MouseEnter " MouseLeave = " item02_MouseLeave " MouseLeftButtonUp = " item02_MouseLeftButtonUp " Canvas.Left = " 95 " Canvas.Top = " 120 " Text = " Start " ></ TextBlock > < TextBlock x:Name = " msg " TextWrapping = " Wrap " Canvas.Left = " 120 " Canvas.Top = " 160 " ></ TextBlock > </ Canvas > </ Grid > </ UserControl >
在这里,刚开始吧image的定义放到textblock后面了,结果鼠标放上去,那个图片一直闪,不稳定.调换后就好了.
2.MenuControl.xaml.cs文件:
using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Browser; namespace DemoApp
相关文章: