示例#1
0
        /// <summary>
        /// Property Changed Callback method of the Owner Dependency Property.
        /// </summary>
        /// <param name="sender">The instance of the class that had the Owner property changed.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void OnOwnerChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            SettingBase       subject  = (SettingBase)sender;
            SettingCollection newValue = (SettingCollection)e.NewValue;
            SettingCollection oldValue = (SettingCollection)e.OldValue;

            if (newValue != null && subject.ValueType != null)
            {
                newValue.SettingsFile.AddValueType(subject.ValueType);
            }
        }
示例#2
0
        /// <summary>
        /// Property Changed Callback method of the Owner Dependency Property.
        /// </summary>
        /// <param name="sender">The instance of the class that had the Owner property changed.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void OnOwnerChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            WindowStateSetting subject  = (WindowStateSetting)sender;
            SettingCollection  newValue = (SettingCollection)e.NewValue;
            SettingCollection  oldValue = (SettingCollection)e.OldValue;

            if (newValue != null)
            {
                newValue.Initializing += subject.SettingCollection_Initializing;
                newValue.Initialized  += subject.SettingCollection_Initialized;
            }
            if (oldValue != null)
            {
                oldValue.Initializing -= subject.SettingCollection_Initializing;
                newValue.Initialized  -= subject.SettingCollection_Initialized;
            }
        }
示例#3
0
        private void SettingCollection_Initializing(object sender, System.EventArgs e)
        {
            SettingCollection subject = (SettingCollection)sender;
            Window            window  = subject.Owner as Window;

            if (window == null)
            {
                throw new InvalidOperationException(String.Format("The {0}'s owner must be a Window.", typeof(WindowStateSetting).Name));
            }

            // Back up the original window position and size in case the restored one is not valid.
            this.positionAndSizeBackup = new int[]
            {
                (int)window.Left,
                (int)window.Top,
                (int)window.ActualWidth,
                (int)window.ActualHeight
            };
        }
示例#4
0
        /// <summary>
        /// Property Changed Callback method of the Settings Dependency Property.
        /// </summary>
        /// <param name="sender">The instance of the class that had the Settings property changed.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void OnSettingsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            FrameworkElement  subject  = (FrameworkElement)sender;
            SettingCollection newValue = (SettingCollection)e.NewValue;
            SettingCollection oldValue = (SettingCollection)e.OldValue;

            if (newValue != null)
            {
                if (newValue.Owner != null)
                {
                    throw new InvalidOperationException("You cannot assign the same settings to two different framework elements.");
                }

                newValue.Owner = subject;
            }

            if (oldValue != null)
            {
                oldValue.Owner = null;
            }
        }
示例#5
0
        private void SettingCollection_Initialized(object sender, System.EventArgs e)
        {
            SettingCollection subject = (SettingCollection)sender;
            Window            window  = (Window)subject.Owner;

            // Restore the original window position and size in case the window is outside the desktop working area.
            int    left   = (int)window.Left;
            int    top    = (int)window.Top;
            int    width  = (int)window.ActualWidth;
            int    height = (int)window.ActualHeight;
            Screen screen = Screen.FromRectangle(new Rectangle(left, top, width, height));

            if (screen == null ||
                !(screen.WorkingArea.Contains(new DPoint(left + TOLERANCE_X, top + TOLERANCE_Y)) ||
                  screen.WorkingArea.Contains(new DPoint(left + width - TOLERANCE_X, top + TOLERANCE_Y))))
            {
                window.Left   = this.positionAndSizeBackup[0];
                window.Top    = this.positionAndSizeBackup[1];
                window.Width  = this.positionAndSizeBackup[2];
                window.Height = this.positionAndSizeBackup[3];
            }

            this.positionAndSizeBackup = null;
        }
示例#6
0
 /// <summary>
 /// Property setter method of Settings Dependency Property.
 /// TODO: (PS) Comment this.
 /// </summary>
 /// <param name="subject">The subject.</param>
 /// <param name="value">The supposed value of the Settings property.</param>
 public static void SetSettings(this FrameworkElement subject, SettingCollection value)
 {
     subject.SetValue(SettingsProperty, value);
 }