JosephGarrone
JosephGarrone

Reputation: 4161

Accessing XAML Object Variables in XAML

So, what I'm trying to do is access my Form's width and/or height to use in a storyboard. Essentially, I have a Translate Transform animation to slide what are essentially two pages. The animation works fine with hard coded From/To variables, however I need to use soft variables that enable the animation to start from the left/right of my form no matter what size it is.

<Storyboard x:Key="SlideLeftToRight"  
                TargetProperty="RenderTransform.(TranslateTransform.X)"
                AccelerationRatio=".4"
                DecelerationRatio=".4">
     <DoubleAnimation Storyboard.TargetName="PageViewer" Duration="0:0:0.6" From="WindowWidth" To="0"/>
     <DoubleAnimation Storyboard.TargetName="BorderVisual" Duration="0:0:0.6" From="0" To="NegativeWindowWidth"/>
</Storyboard>

However, I have no idea how to do so. Any help is greatly appreciated.

EDIT: I'm guessing it has something to do with:

From="{Binding Width, Source=MainWindow}"

However, when I attempt this, I don't know how to make it negative.

Upvotes: 0

Views: 370

Answers (1)

Fede
Fede

Reputation: 44028

Use ElementName=MainWindow instead, and use ActualWidth instead of Width

From="{Binding ActualWidth, ElementName=MainWindow}"/>

(Make sure you have x:Name=MainWindow in the window, too.

If you want the negative of the current value, you will have to use a Converter.

Upvotes: 1

Related Questions