Click here to Skip to main content
15,892,537 members
Articles / Desktop Programming / WPF

Motion adjuster application – using Ultrabook Sensors

Rate me:
Please Sign up or sign in to vote.
4.82/5 (11 votes)
26 May 2013CPOL2 min read 27.2K   262   7  
Using sensors, we can get the change in X and Y direction (i.e. movement), using which we can adjust laptop screen to make it very stable although having jerking motion.
namespace MotionAdjusterApp
{
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Media.Animation;
    using Windows.UI.Xaml.Navigation;

    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        /// <summary>
        /// Member variable for moving container storyboard.
        /// </summary>
        private Storyboard moveContainerBorder = null;
        
        /// <summary>
        /// Member variable for moving container with adjuster storyboard.
        /// </summary>
        private Storyboard moveContainerBorderWithAdjuster = null;

        public MainPage()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Occurs when MainPage loads.
        /// </summary>
        /// <param name="sender">
        /// MainPage instance.
        /// </param>
        /// <param name="e">
        /// Event argument.
        /// </param>
        private void samplePage_Loaded(object sender, RoutedEventArgs e)
        {
            this.moveContainerBorder = this.Resources["moveContainerBorder"] as Storyboard;
            this.moveContainerBorderWithAdjuster = this.Resources["moveContainerBorderWithAdjuster"] as Storyboard;
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        /// <summary>
        /// Occurs when "Start Motion" button is clicked.
        /// </summary>
        /// <param name="sender">
        /// startMotionButton instance.
        /// </param>
        /// <param name="e">
        /// Event argument.
        /// </param>
        private void startMotionButton_Click(object sender, RoutedEventArgs e)
        {
            this.moveContainerBorder.Begin();
        }

        /// <summary>
        /// Occurs when "Stop Motion" button is clicked.
        /// </summary>
        /// <param name="sender">
        /// stopMotionButton instance.
        /// </param>
        /// <param name="e">
        /// Event argument.
        /// </param>
        private void stopMotionButton_Click(object sender, RoutedEventArgs e)
        {
            this.moveContainerBorder.Stop();
            this.moveContainerBorderWithAdjuster.Stop();
        }

        /// <summary>
        /// Occurs when "Motion with Motion Adjuster" button is clicked.
        /// </summary>
        /// <param name="sender">
        /// adjustMotionButton instance.
        /// </param>
        /// <param name="e">
        /// Event argument.
        /// </param>
        private void motionAdjusterButton_Click(object sender, RoutedEventArgs e)
        {
            this.moveContainerBorderWithAdjuster.Begin();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) iGATE Computer Systems Ltd.
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions