Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So the problem is with how you're using your user control - you simply override content once specified inside UserControl xaml definition... anyway.. Try this approach (animation works on my machine so suppose to work on yours as well ;))</p> <pre><code>&lt;UserControl x:Class="WpfApplication11.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="300" d:DesignWidth="300" mc:Ignorable="d"&gt; &lt;UserControl.Template&gt; &lt;ControlTemplate TargetType="UserControl"&gt; &lt;Grid Background="Coral"&gt; &lt;Canvas&gt; &lt;ContentPresenter x:Name="MNB" Content="{TemplateBinding Content}"/&gt; &lt;/Canvas&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/UserControl.Template&gt; </code></pre> <p></p> <p>And in animation itself:</p> <pre><code> private void AnimatedUserControl2_OnIsVisibleChanged(object sender, EventArgs e) { var mnb = Template.FindName("MNB", this) as FrameworkElement; if (mnb == null) { return; } if (Visibility == Visibility.Visible) { var storyboard = new Storyboard(); var visibilityAnimation = new ObjectAnimationUsingKeyFrames(); visibilityAnimation.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Visible, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)))); Storyboard.SetTargetProperty(visibilityAnimation, new PropertyPath(VisibilityProperty)); storyboard.Children.Add(visibilityAnimation); var opacityAnimation = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(1))); Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(OpacityProperty)); storyboard.Children.Add(opacityAnimation); var canvasLeftAnimation = new DoubleAnimationUsingKeyFrames(); canvasLeftAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(200, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)))); canvasLeftAnimation.KeyFrames.Add(new SplineDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)), new KeySpline(new Point(0.25, 0.1), new Point(0.25, 1)))); Storyboard.SetTargetProperty(canvasLeftAnimation, new PropertyPath(Canvas.LeftProperty)); storyboard.Children.Add(canvasLeftAnimation); mnb.BeginStoryboard(storyboard, HandoffBehavior.SnapshotAndReplace, false); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload