0

I am new to WPF and just starting to get used to it, I want to move a page across the screen when I load it. The Code I using for that currently is :

<Storyboard>
    <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" BeginTime="00:00:00">
        <SplineThicknessKeyFrame KeyTime="00:00:00" Value="1920,0,0,0" />
        <SplineThicknessKeyFrame KeyTime="00:00:02" Value="0,0,0,0" />
    </ThicknessAnimationUsingKeyFrames>
    <DoubleAnimation
            Storyboard.TargetName="SummaryPageName"
            Storyboard.TargetProperty="Opacity"
            From="0" To="1" Duration="0:0:2"
            AutoReverse="False">
    </DoubleAnimation>
</Storyboard>

While this works fine for me, what I want is to not use hard values(1920) in value field of

<SplineThicknessKeyFrame KeyTime="00:00:00" Value="1920,0,0,0" />

Is there anyway to do that without specifying this value, so that it will work with other resolutions as well.

Thank you

Timo Salomäki
  • 7,099
  • 3
  • 25
  • 40
Manal Goyal
  • 29
  • 1
  • 8
  • I recommand you to bind the Value to your viewmodel properties. Then you will be able to get your screen resolution, I think you must have a look to : https://stackoverflow.com/questions/5082610/get-and-set-screen-resolution – pix Aug 28 '17 at 12:24

1 Answers1

0

Modify the KeyFrame value with code behind. You should assign resource name to the storyboard resource to be found by code behind.

[XAML]
<Storyboard x:Key="myStoryboard">

Get the Storyboard object instance by referring x:Key.

[C#]
private void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e)
{
    Storyboard s = this.Resources["myStoryboard"] as Storyboard;
    SplineThicknessKeyFrame k = (s.Children[0] as ThicknessAnimationUsingKeyFrames).KeyFrames[0] as SplineThicknessKeyFrame;
    k.Value = new Thickness(e.NewSize.Width,0,0,0);
}

Also you may use data binding to change keyframe value. If you need to change a lot of keyframe resources, you should use data binding. Otherwise changing value manually is easy to prepare.

Teddy.K
  • 16