SilverLight代码添加交互性DropShadowEffect
首先要引用命名空间:System.Windows.Media.Effects.DropShadowEffect
以下是实现一个很简单的功能,只要鼠标移到button上就启动特效。鼠标离开时清除特效:
a)xaml部分:
?<Grid?x:Name="LayoutRoot"?Background="White">
????????<Button?Content="Button"?Height="23"?HorizontalAlignment="Left"?Margin="10,10,0,0"?
???????????????????Name="button1"?VerticalAlignment="Top"?Width="75"?/>
?</Grid>
b)c#部份:
namespace?SilverlightApplication20
{?
public?partial?class?MainPage?:?UserControl?
{?
public?MainPage()?
?{?
?InitializeComponent();?
button1.MouseEnter?+=?new?MouseEventHandler(button1_MouseEnter);?
?button1.MouseLeave?+=?new?MouseEventHandler(button1_MouseLeave);
?}
?void?button1_MouseLeave(object?sender,?MouseEventArgs?e)
{
button1.Effect?=?null;
?}
void?button1_MouseEnter(object?sender,?MouseEventArgs?e)
{
?System.Windows.Media.Effects.DropShadowEffect?ds?=?new?System.Windows.Media.Effects.DropShadowEffect();
ds.ShadowDepth?=?0;
ds.Color?=?Colors.Yellow;
?button1.Effect?=?ds;
?}
?}
?}