Exemplo n.º 1
0
        } // OnFrameworkElementSettingsChanged

        // ----------------------------------------------------------------------
        private static void OnCollectedSettingChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
        {
            FrameworkElement frameworkElement = dependencyObject as FrameworkElement;

            if (frameworkElement == null)
            {
                Debug.WriteLine("FrameworkElementSettings: invalid framework element");
                return;
            }

            DependencyProperty dependencyProperty = e.NewValue as DependencyProperty;

            if (dependencyProperty == null)
            {
                Debug.WriteLine("FrameworkElementSettings: missing dependency property");
                return;
            }

            // search the framework element settings
            FrameworkElementSettings frameworkElementSettings =
                frameworkElement.ReadLocalValue(DependencyPropertySetting.ApplicationSettingsProperty) as FrameworkElementSettings;

            if (frameworkElementSettings == null)
            {
                Debug.WriteLine("FrameworkElementSettings: missing framework element settings in element " + frameworkElement);
                return;
            }

            DependencyPropertySettingCollector collector =
                new DependencyPropertySettingCollector(frameworkElement, dependencyProperty);

            frameworkElementSettings.SettingCollectors.Add(collector);
        } // OnCollectedSettingChanged
Exemplo n.º 2
0
        } // WindowClosing

        // ----------------------------------------------------------------------
        private static void OnFrameworkElementSettingsChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
        {
            FrameworkElement frameworkElement = dependencyObject as FrameworkElement;

            if (frameworkElement == null)
            {
                Debug.WriteLine("FrameworkElementSettings: invalid framework element");
                return;
            }

            if (frameworkElement.GetValue(DependencyPropertySetting.ApplicationSettingsProperty) != null)
            {
                return; // framework-element contains already an application setting
            }

            string settingsKey = e.NewValue as string;

            if (string.IsNullOrEmpty(settingsKey))
            {
                Debug.WriteLine("FrameworkElementSettings: missing framework element settings key");
                return;
            }

            // create and attach the application settings to the framework-element
            FrameworkElementSettings frameworkElementSettings = new FrameworkElementSettings(frameworkElement, settingsKey);

            frameworkElement.SetValue(DependencyPropertySetting.ApplicationSettingsProperty, frameworkElementSettings);
        } // OnFrameworkElementSettingsChanged
        } // WindowClosing

        // ----------------------------------------------------------------------
        private static void OnFrameworkElementSettingsChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
        {
            FrameworkElement frameworkElement = dependencyObject as FrameworkElement;
            if (frameworkElement == null)
            {
                Debug.WriteLine("FrameworkElementSettings: invalid framework element");
                return;
            }

            if (frameworkElement.GetValue(DependencyPropertySetting.ApplicationSettingsProperty) != null)
            {
                return; // framework-element contains already an application setting
            }

            string settingsKey = e.NewValue as string;
            if (string.IsNullOrEmpty(settingsKey))
            {
                Debug.WriteLine("FrameworkElementSettings: missing framework element settings key");
                return;
            }

            // create and attach the application settings to the framework-element
            FrameworkElementSettings frameworkElementSettings = new FrameworkElementSettings(frameworkElement, settingsKey);
            frameworkElement.SetValue(DependencyPropertySetting.ApplicationSettingsProperty, frameworkElementSettings);
        } // OnFrameworkElementSettingsChanged