Exemplo n.º 1
0
        }         // WindowClosing

        // ----------------------------------------------------------------------
        private DependencyPropertySetting CreateSetting(string name, DependencyProperty dependencyProperty)
        {
            DependencyPropertySetting propertySetting = new DependencyPropertySetting(name, window, dependencyProperty);

            propertySetting.ValueSaving += ValueSaving;
            return(propertySetting);
        }         // CreateSetting
Exemplo n.º 2
0
        }         // Collect

        // ----------------------------------------------------------------------
        private void Collect(DependencyObject currentObject, bool recursive)
        {
            foreach (object child in LogicalTreeHelper.GetChildren(currentObject))
            {
                DependencyObject dependencyObject = child as DependencyObject;
                if (dependencyObject == null)
                {
                    continue;
                }

                FrameworkElement frameworkElement = child as FrameworkElement;
                if (frameworkElement != null)
                {
// ReSharper disable UseMethodIsInstanceOfType
                    bool add = dependencyProperty.OwnerType.IsAssignableFrom(frameworkElement.GetType());
// ReSharper restore UseMethodIsInstanceOfType

                    if (add && string.IsNullOrEmpty(frameworkElement.Name))
                    {
                        add = false;
                        Debug.WriteLine("DependencyPropertySettingCollector: missing name for framework element " + frameworkElement);
                    }

                    if (add && !OnCollectingSetting(frameworkElement))
                    {
                        add = false;
                    }

                    if (add)
                    {
                        string settingName = string.Concat(frameworkElement.Name, ".", dependencyProperty.Name);
                        DependencyPropertySetting dependencyPropertySetting =
                            new DependencyPropertySetting(settingName, frameworkElement, dependencyProperty);
                        dependencyPropertySetting.DefaultValue = dependencyPropertySetting.Value;
                        ApplicationSettings.Settings.Add(dependencyPropertySetting);
                    }
                }

                if (recursive)
                {
                    Collect(dependencyObject, true);
                }
            }
        }         // Collect
		} // Collect

		// ----------------------------------------------------------------------
		private void Collect( DependencyObject currentObject, bool recursive )
		{
			foreach ( object child in LogicalTreeHelper.GetChildren( currentObject ) )
			{
				DependencyObject dependencyObject = child as DependencyObject;
				if ( dependencyObject == null )
				{
					continue;
				}

				FrameworkElement frameworkElement = child as FrameworkElement;
				if ( frameworkElement != null )
				{
// ReSharper disable UseMethodIsInstanceOfType
					bool add = dependencyProperty.OwnerType.IsAssignableFrom( frameworkElement.GetType() );
// ReSharper restore UseMethodIsInstanceOfType

					if ( add && string.IsNullOrEmpty( frameworkElement.Name ) )
					{
						add = false;
						Debug.WriteLine( "DependencyPropertySettingCollector: missing name for framework element " + frameworkElement );
					}

					if ( add && !OnCollectingSetting( frameworkElement ) )
					{
						add = false;
					}

					if ( add )
					{
						string settingName = string.Concat( frameworkElement.Name, ".", dependencyProperty.Name );
						DependencyPropertySetting dependencyPropertySetting =
							new DependencyPropertySetting( settingName, frameworkElement, dependencyProperty );
						dependencyPropertySetting.DefaultValue = dependencyPropertySetting.Value;
						ApplicationSettings.Settings.Add( dependencyPropertySetting );
					}
				}

				if ( recursive )
				{
					Collect( dependencyObject, true );
				}
			}
		} // Collect