1.为了在XAML中使用到Blend提供的MVVM框架,需要添加以下命名空间进行引用:
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ei="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
或者
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
2.不写C#代码在图片加载的时候实现透明度渐变动画:
<Image x:Name="myImage" Source="http://www.silverlightinaction.com/man.png">
<!--图片触发器-->
<Image.Triggers>
<!--图片加载事件触发器-->
<EventTrigger RoutedEvent="Image.Loaded">
<!--开始播放故事版动画-->
<BeginStoryboard>
<Storyboard x:Name="myStoryboard">
<DoubleAnimation Duration="0:0:2"
Storyboard.TargetName="myImage"
Storyboard.TargetProperty="Opacity"
From="0" To="1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
</Image>
3.View层调用ViewModel层中的方法:
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<!--TargetObject绑定持有该事件的对应元素-->
<ei:CallMethodAction MethodName="Close" TargetObject="{Binding}" />
</i:EventTrigger>
</i:Interaction.Triggers>
4.