It would seem a trivial task and an error in something less, but simply supported Loaded
and that's it. Everything is connected because of the change from Silverlight
. Rotate this case with the Behaviors SDK (XAML)
Add Library References -> Add Reference ...

Add references to the namespace:
xmlns:i="using:Microsoft.Xaml.Interactivity" xmlns:core="using:Microsoft.Xaml.Interactions.Core" xmlns:media="using:Microsoft.Xaml.Interactions.Media"
We rewrite your code a little
<Border Height="50" HorizontalAlignment="Stretch" CornerRadius="5" x:Name="MyBorder" BorderBrush="#9e9e9e" Background="#ff567cd3" BorderThickness="0 0 0 3"> <i:Interaction.Behaviors> <core:EventTriggerBehavior EventName="Tapped"> <media:ControlStoryboardAction Storyboard="{StaticResource ColorStoryboard}"/> </core:EventTriggerBehavior> </i:Interaction.Behaviors> <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20" FontWeight="SemiBold" Foreground="#fff" Text="Нажми меня"/> </Border>
Added x: Name to Border
for which we will animate the Background
. The animation itself is not located inside the media:ControlStoryboardAction
, this is due to the fact that Behavior
is not in the element tree, hence it does not have access to the Border
by x:Name
:
<Page.Resources> <Storyboard x:Name="ColorStoryboard"> <ColorAnimationUsingKeyFrames Storyboard.TargetName="MyBorder" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" Duration="0:0:0.3" EnableDependentAnimation="True"> <LinearColorKeyFrame Value="#ff9e9e9e" KeyTime="0:0:0.15"/> <LinearColorKeyFrame Value="#ff567cd3" KeyTime="0:0:0.3"/> </ColorAnimationUsingKeyFrames> </Storyboard> </Page.Resources>
UPDATE
If you need to change something else, then it is worth noting that when declaring elements inside the 'Storyboard', they are added to the TimelineCollection
. Add x:Name="MyTextBlock"
to our TextBlock
and update the animation:
<Storyboard x:Name="ColorStoryboard"> <ColorAnimationUsingKeyFrames Storyboard.TargetName="MyBorder" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" Duration="0:0:0.3" EnableDependentAnimation="True"> <LinearColorKeyFrame Value="#ff9e9e9e" KeyTime="0:0:0.15"/> <LinearColorKeyFrame Value="#ff567cd3" KeyTime="0:0:0.3"/> </ColorAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MyTextBlock" Storyboard.TargetProperty="Text"> <DiscreteObjectKeyFrame KeyTime="0" Value="Спасибо"/> </ObjectAnimationUsingKeyFrames> </Storyboard>