コード例 #1
0
ファイル: StateUtils.cs プロジェクト: misenhower/WPRemote
        /// <summary>
        /// Retrieves the saved scroll offset from the state dictionary and creates a delegate to
        /// restore the scroll position on the page's first render.
        /// </summary>
        /// <param name="state"></param>
        /// <param name="scrollViewer"></param>
        public static void RestoreState(this PhoneApplicationPage page, ScrollViewer scrollViewer)
        {
            double offset = page.TryGetStateValue <double>(scrollViewer.Name + "_HorizontalOffset", 0);

            if (offset > 0)
            {
                ScheduleOnNextRender(delegate { scrollViewer.ScrollToHorizontalOffset(offset); });
            }
            offset = page.TryGetStateValue <double>(scrollViewer.Name + "_VerticalOffset", 0);
            if (offset > 0)
            {
                ScheduleOnNextRender(delegate { scrollViewer.ScrollToVerticalOffset(offset); });
            }
        }
コード例 #2
0
ファイル: StateUtils.cs プロジェクト: misenhower/WPRemote
        /// <summary>
        /// Retrieves the name of the control that should have focus and creates a delegate to
        /// restore the scroll position on the page's first render.
        /// </summary>
        /// <param name="state">The calling page's state dictionary.</param>
        /// <param name="parent">The parent element for which focus is being restored.</param>
        public static void RestoreFocusState(this PhoneApplicationPage page, FrameworkElement parent)
        {
            // Get the name of the control that should have focus.
            string focusedName = page.TryGetStateValue <string>("FocusedElementName", null);

            // Check to see if the name is null or empty
            if (!String.IsNullOrEmpty(focusedName))
            {
                // Find the control name in the parent.
                Control focusedControl = parent.FindName(focusedName) as Control;
                if (focusedControl != null)
                {
                    // If the control is found, schedule a call to its Focus method for the next render.
                    ScheduleOnNextRender(delegate { focusedControl.Focus(); });
                }
            }
        }
コード例 #3
0
ファイル: StateUtils.cs プロジェクト: misenhower/WPRemote
 /// <summary>
 /// Restores the value of a Slider from the page's state dictionary.
 /// </summary>
 /// <param name="state">The calling page's state dictionary.</param>
 /// <param name="slider">The Slider to be restored.</param>
 /// <param name="defaultValue">A default value that is used if the saved value cannot be retrieved.</param>
 public static void RestoreState(this PhoneApplicationPage page, Slider slider, double defaultValue)
 {
     slider.Value = page.TryGetStateValue <double>(slider.Name + "_Value", defaultValue);
 }
コード例 #4
0
ファイル: StateUtils.cs プロジェクト: misenhower/WPRemote
 /// <summary>
 /// Restores the checked state of a CheckBox from the page's state dictionary.
 /// </summary>
 /// <param name="state">The calling page's state dictionary.</param>
 /// <param name="checkBox">The CheckBox to be restored.</param>
 /// <param name="defaultValue">A default value that is used if the saved value cannot be retrieved.</param>
 public static void RestoreState(this PhoneApplicationPage page, CheckBox checkBox, bool defaultValue)
 {
     checkBox.IsChecked = page.TryGetStateValue <bool>(checkBox.Name + "_IsChecked", defaultValue);
 }
コード例 #5
0
ファイル: StateUtils.cs プロジェクト: misenhower/WPRemote
 /// <summary>
 /// Restores the contents and selection location of a TextBox from the page's state dictionary.
 /// </summary>
 /// <param name="state">The calling page's state dictionary.</param>
 /// <param name="textBox">The TextBox to be restored.</param>
 /// <param name="defaultValue">A default value that is used if the saved value cannot be retrieved.</param>
 public static void RestoreState(this PhoneApplicationPage page, TextBox textBox, string defaultValue)
 {
     textBox.Text            = page.TryGetStateValue <string>(textBox.Name + "_Text", defaultValue);
     textBox.SelectionStart  = page.TryGetStateValue <int>(textBox.Name + "_SelectionStart", textBox.Text.Length);
     textBox.SelectionLength = page.TryGetStateValue <int>(textBox.Name + "_SelectionLength", 0);
 }
コード例 #6
0
ファイル: StateUtils.cs プロジェクト: misenhower/WPRemote
 public static void RestoreState(this PhoneApplicationPage page, Pivot pivot, int defaultIndex)
 {
     pivot.SelectedIndex = page.TryGetStateValue <int>(pivot.Name + "_SelectedIndex", defaultIndex);
 }
コード例 #7
0
ファイル: StateUtils.cs プロジェクト: misenhower/WPRemote
 /// <summary>
 /// Restores the checked state of a RadioButton from the page's state dictionary.
 /// </summary>
 /// <param name="state">The calling page's state dictionary.</param>
 /// <param name="radioButton">The RadioButton to be restored.</param>
 /// <param name="defaultValue">A default value that is used if the saved value cannot be retrieved.</param>
 public static void RestoreState(this PhoneApplicationPage page, RadioButton radioButton, bool defaultValue)
 {
     radioButton.IsChecked = page.TryGetStateValue <bool>(radioButton.Name + "_IsChecked", defaultValue);
 }