Logo
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
EPL Standings
 
 
Windows Phone

Windows Phone 8 : Orientation and the PhoneApplicationPage Class (part 4) - Animating Page Elements When the Page Orientation Changes

4/28/2014 1:34:08 AM

Animating Page Elements When the Page Orientation Changes

The VisualStateManager can be used to animate UIElements when the page orientation changes. This can be done by defining a set of VisualStateGroups corresponding to the PageOrientation values.

Each VisualStateGroup contains a collection of VisualState objects, each containing a collection of Storyboard objects that specify how an element’s properties change when the control is placed in a particular visual state.

In Listing 3, you see how the LandscapeRight VisualState includes a set of DoubleAnimations, which move various TextBlocks on the page to new positions when the page orientation changes.

LISTING 3. OrientationView.xaml (excerpt)


<Grid x:Name="LayoutRoot">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="OrientationStates">
            <!--Portrait up is the default state-->
            <VisualState x:Name="PortraitUp">
                <Storyboard />
            </VisualState>

            <VisualState x:Name="LandscapeRight">
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="topLeft"
                        Storyboard.TargetProperty="
                            (UIElement.RenderTransform).(TranslateTransform.X)"
                        To="650" />
                    <!-- Content omitted. -->
                </Storyboard>
            </VisualState>
            <!-- Content omitted. -->
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

    <!-- Content omitted. -->

    <Grid x:Name="ContentGrid" Grid.Row="1">
        <TextBlock Text="Top-left corner" x:Name="topLeft"
                HorizontalAlignment="Left" VerticalAlignment="Top">
        <TextBlock.RenderTransform>
            <TranslateTransform/>
        </TextBlock.RenderTransform>
        </TextBlock>
        <!-- Content omitted. -->
    </Grid>
</Grid>


We subscribe to OrientationChanged event within the view’s constructor, as shown in the following excerpt:

OrientationChanged += (sender, args) => VisualStateManager.GoToState(
                                    this, args.Orientation.ToString(), true);

When the OrientationChanged event is raised, the VisualStateManager is directed to the state identified by the Orientation property of the OrientationChangedEventArgs (see Figure 3).

Image

FIGURE 3 TextBlocks are animated into position when page orientation changes.

Other -----------------
- Windows Phone 8 : Working with the Windows Phone Software (part 9) - Copying Phone Content to Your PC or Tablet
- Windows Phone 8 : Working with the Windows Phone Software (part 8) - Removing Multimedia Content - Removing Pictures from Your Phone
- Windows Phone 8 : Working with the Windows Phone Software (part 7) - Removing Multimedia Content - Removing a Video from Your Phone
- Windows Phone 8 : Working with the Windows Phone Software (part 6) - Removing Multimedia Content - Removing Music from Your Phone
- Windows Phone 8 : Working with the Windows Phone Software (part 5) - Using the Photo Interface
- Windows Phone 8 : Working with the Windows Phone Software (part 4) - Adding Content from Nonstandard Locations
- Windows Phone 8 : Working with the Windows Phone Software (part 3) - Adding an Album to Your Phone,Adding a Musical Artist to Your Phone
- Windows Phone 8 : Working with the Windows Phone Software (part 2) - Adding Videos to Your Phone,Adding a Song to Your Phone
- Windows Phone 8 : Working with the Windows Phone Software (part 1) - Adding Photos to Your Phone
- Windows Phone 8 : Configuring Basic Device Settings - Phone Storage
- Windows Phone 8 : Configuring Basic Device Settings - Battery Saver
- Windows Phone 8 : Configuring Basic Device Settings - Backing Up Your Phone (part 5) - Restoring Your Backups
- Windows Phone 8 : Configuring Basic Device Settings - Backing Up Your Phone (part 4) - Determining Backup Quality for Your Photos and Videos
- Windows Phone 8 : Configuring Basic Device Settings - Backing Up Your Phone (part 3) - Backing Up Text Messages
- Windows Phone 8 : Configuring Basic Device Settings - Backing Up Your Phone (part 2) - Removing Your Backup
- Windows Phone 8 : Configuring Basic Device Settings - Backing Up Your Phone (part 1) = Backing Up App Lists and Settings
- Windows Phone 8 : Configuring Basic Device Settings - Providing Feedback
- Windows Phone 8 : Configuring Basic Device Settings - About Your Phone
- Windows Phone 8 : Configuring Basic Device Settings - Find My Phone
- Windows Phone 8 : Configuring Basic Device Settings - Accessibility (part 2) - Enabling the Screen Magnifier, Using Speech for Phone Accessibility
 
 
Most view of day
- Windows Phone 8 : Configuring Basic Device Settings - Wi-Fi Networking (part 1) - Enabling or Disabling Wi-Fi, Connecting to a Wi-Fi Network
- Windows Server 2012 : Deploying Storage Spaces (part 4) - Planning a Storage Spaces deployment - Availability, Management
- Microsoft Dynamics CRM 4.0 : SharePoint Integration - Custom SharePoint Development
- Adobe After Effects CS5 : Building a 3D object - Working with a null object
- Exchange Server 2007 : Migrating from Windows 2000 Server to Windows Server 2003 (part 2) - Upgrading a Single Member Server
- Exchange Server 2007 : Using OWA Mail Features (part 3)
- Windows Server 2008 : Designing the Active Directory Administrative Model (part 3) - Planning to Audit AD DS and Group Policy Compliance, Planning Organizational Structure
- Windows Phone 7 Programming Model : Device Information
- SharePoint 2010 : Packaging and Deployment Model - Site Definitions
- Creating DVD Movies with Windows DVD Maker (part 2) - Adding Photos and Videos to Your DVD Project - DVD Storage Issues and Formats , Arranging Content
Top 10
- Windows Server 2012 : DHCP,IPv6 and IPAM - Exploring DHCP (part 3) - Creating IPv4 DHCP Scopes
- Windows Server 2012 : DHCP,IPv6 and IPAM - Exploring DHCP (part 2) - Installing DHCP Server and Server Tools
- Windows Server 2012 : DHCP,IPv6 and IPAM - Exploring DHCP (part 1)
- Windows Server 2012 : DHCP,IPv6 and IPAM - Understanding the Components of an Enterprise Network
- Microsoft OneNote 2010 : Using the Research and Translate Tools (part 3) - Translating Text with the Mini Translator
- Microsoft OneNote 2010 : Using the Research and Translate Tools (part 2) - Translating a Word or Phrase with the Research Pane
- Microsoft OneNote 2010 : Using the Research and Translate Tools (part 1) - Setting Options for the Research Task Pane, Searching with the Research Task Pane
- Microsoft OneNote 2010 : Doing Research with Linked Notes (part 2) - Ending a Linked Notes Session, Viewing Linked Notes
- Microsoft OneNote 2010 : Doing Research with Linked Notes (part 1) - Beginning a Linked Notes Session
- Microsoft OneNote 2010 : Doing Research with Side Notes (part 3) - Moving Side Notes to Your Existing Notes
 
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro