<ControlTemplate targettype="me:MyControl" x:Key="fade"> <ContentPresenter - other stuff /> <ControlTemplate.Triggers> <Trigger Property="IsTransitioned" Value="True"> <Trigger.Enteractions> <BeginStoryboard> <Storyboard> <DoubleAnimation -<stuff>- /> </Storyboard> </BeginStoryboard> </Trigger.Enteractions> </Trigger> </ControlTemplate.Triggers></ControlTemplate>
这在WPF中很酷,对我来说也非常直观,我可以根据上面的触发器来编写它.
当我将其移植到Silverlight(3)时,我被告知我必须使用VSM,状态和组等,因为不支持控件模板上的触发器.
我已经看了一些样本,我甚至尝试在上面的触发位置应用了VSM位,但无法使其工作.
有人向我建议,除了xaml中的VSM,我将不得不处理一些事件等.
SL3模型对我来说很痛苦.请帮忙.
解决方法 Silverlight 3引入了交互触发器,据我所知,你可以做什么,但有点复杂.尽管如此,关于它们的例子很少.如果您手动执行此 *** 作,则需要引用System.windows.Interactivity和Microsoft.Expression.Interactions(来自Blend 3,如果已安装,该类将位于引用选项卡中).
如果在Blend中添加触发器,则会自动添加这些触发器.这在Silverlight 3中称为“行为”,您可以在“资源”选项卡的“行为”部分的“混合”中找到这些行为.
他们如何工作的一个例子.注意位于第二个矩形的资源中的故事板,我无法让它在ControlStoryboardAction.Storyboard中工作,但如果我将矩形设为ContentControl并将其放入模板中,它确实有效.这可能是一个错误或我错过了一些东西:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="SLTrigger.MainPage" xmlns:i="clr-namespace:System.windows.Interactivity;assembly=System.windows.Interactivity" xmlns:ic="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions" xmlns:im="clr-namespace:Microsoft.Expression.Interactivity.Media;assembly=Microsoft.Expression.Interactions"> <GrID x:name="LayoutRoot"> <StackPanel> <Rectangle margin="5" Fill="Blue" WIDth="200" Height="100"> <i:Interaction.Triggers> <i:EventTrigger Eventname="MouseleftbuttonDown"> <ic:ChangePropertyAction Propertyname="Fill" Duration="0"> <ic:ChangePropertyAction.Value> <SolIDcolorBrush color="Red"/> </ic:ChangePropertyAction.Value> </ic:ChangePropertyAction> </i:EventTrigger> </i:Interaction.Triggers> </Rectangle> <Rectangle margin="5" x:name="AnimatedRectangle2" Fill="Blue" WIDth="200" Height="100"> <Rectangle.Resources> <Storyboard x:Key="AnimationStoryboard"> <colorAnimation Storyboard.Targetname="AnimatedRectangle2" Storyboard.TargetProperty="(Shape.Fill).(SolIDcolorBrush.color)" To="Red" autoReverse="True" Duration="0:0:0.5" /> </Storyboard> </Rectangle.Resources> <i:Interaction.Triggers> <i:EventTrigger Eventname="MouseleftbuttonDown"> <im:ControlStoryboardAction ControlStoryboardOption="Play" Storyboard="{StaticResource AnimationStoryboard}"> <!-- Doesn't work,but does work insIDe control templates?? <im:ControlStoryboardAction.Storyboard> <Storyboard> <colorAnimation Storyboard.Targetname="AnimatedRectangle2" Storyboard.TargetProperty="(Shape.Fill).(SolIDcolorBrush.color)" To="Red" autoReverse="True" Duration="0:0:0.5" /> </Storyboard> </im:ControlStoryboardAction.Storyboard> --> </im:ControlStoryboardAction> </i:EventTrigger> </i:Interaction.Triggers> </Rectangle> <ContentControl> <ContentControl.Template> <ControlTemplate> <Rectangle margin="5" x:name="AnimatedRectangle3" Fill="Blue" WIDth="200" Height="100"> <i:Interaction.Triggers> <i:EventTrigger Eventname="MouseleftbuttonDown"> <im:ControlStoryboardAction ControlStoryboardOption="Play"> <im:ControlStoryboardAction.Storyboard> <Storyboard> <colorAnimation Storyboard.Targetname="AnimatedRectangle3" Storyboard.TargetProperty="(Shape.Fill).(SolIDcolorBrush.color)" To="Red" autoReverse="True" Duration="0:0:0.5" /> </Storyboard> </im:ControlStoryboardAction.Storyboard> </im:ControlStoryboardAction> </i:EventTrigger> </i:Interaction.Triggers> </Rectangle> </ControlTemplate> </ContentControl.Template> </ContentControl> <TextBlock TextAlignment="Center" Text="Click the rectangles" /> </StackPanel> </GrID></UserControl>
类文件中没有任何内容:
using System.windows.Controls;namespace SLTrigger{ public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } }}总结
以上是内存溢出为你收集整理的ControlTemplate.Triggers Silverlight 3中的WPF等效项全部内容,希望文章能够帮你解决ControlTemplate.Triggers Silverlight 3中的WPF等效项所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)