Вход на сайт
Воспоминание Microsoft Silverlight 08.10.2024
1449 просмотров
Перейти к просмотру всей ветки
в ответ uscheswoi_82 09.10.24 09:37
Продолжим болтавню. Теперь давайте сделаем простую анимацию.
Вот код Page.xaml:
<Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="640" Height="480" Background="White" x:Name="Page"> <Canvas.Resources> <Storyboard x:Name="Storyboard1"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="rectangle" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"> <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/> <SplineDoubleKeyFrame KeyTime="00:00:08.9000000" Value="168"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="rectangle" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)"> <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/> <SplineDoubleKeyFrame KeyTime="00:00:08.9000000" Value="59"/> </DoubleAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="rectangle" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"> <SplineColorKeyFrame KeyTime="00:00:00" Value="#FF6299DC"/> <SplineColorKeyFrame KeyTime="00:00:08.9000000" Value="#FFDCC762"/> </ColorAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="rectangle" Storyboard.TargetProperty="(Rectangle.RadiusX)"> <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/> <SplineDoubleKeyFrame KeyTime="00:00:08.9000000" Value="31.5"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="rectangle" Storyboard.TargetProperty="(Rectangle.RadiusY)"> <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/> <SplineDoubleKeyFrame KeyTime="00:00:08.9000000" Value="31.5"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </Canvas.Resources> <Rectangle Fill="#FF6299DC" Stroke="#FF000000" Canvas.Left="149" Canvas.Top="39" Width="181" Height="67" x:Name="rectangle" RenderTransformOrigin="0.5,0.5"> <Rectangle.RenderTransform> <TransformGroup> <ScaleTransform ScaleX="1" ScaleY="1"/> <SkewTransform AngleX="0" AngleY="0"/> <RotateTransform Angle="0"/> <TranslateTransform X="0" Y="0"/> </TransformGroup> </Rectangle.RenderTransform> </Rectangle> <Canvas Canvas.Left="142.5" Canvas.Top="437.5" Width="84" Height="32" x:Name="play" Cursor="Hand"> <Rectangle Fill="#FF30A0E0" Stroke="#FF000000" RadiusX="4.5" RadiusY="4.5" Width="84" Height="32"/> <TextBlock Canvas.Left="22.5" Canvas.Top="3.5" Width="39" Height="25" TextWrapping="Wrap"><Run Text="Пуск"/></TextBlock> </Canvas> <Canvas Canvas.Left="245.5" Canvas.Top="437.5" Cursor="Hand" x:Name="stop" Width="84" Height="32"> <Rectangle Fill="#FF30A0E0" Stroke="#FF000000" RadiusX="4.5" RadiusY="4.5" Width="84" Height="32"/> <TextBlock Canvas.Left="22.5" Canvas.Top="3.5" Width="39" Height="25" TextWrapping="Wrap"><Run Text="Стоп"/></TextBlock> </Canvas> </Canvas>
Вот код Page.xaml.js:
if (!window.SilverlightSite) SilverlightSite = {}; SilverlightSite.Page = function() {} SilverlightSite.Page.prototype = { handleLoad: function(control, userContext, rootElement) { this.control = control; this.control.content.findName("play").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown)); this.control.content.findName("stop").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown)); }, handleMouseDown: function(sender, eventArgs) { if(sender.name == 'play') this.control.content.findName("Storyboard1").Begin(); if(sender.name == 'stop') this.control.content.findName("Storyboard1").Stop(); }}
А вот и результат:
Если я кому-то отвечаю, это не значит что я ему симпатизирую, каждый остаётся при своём мнение