public DependencyPropertyViewModel(
            DependencyObjectViewModel elementViewModel,
            DependencyPropertyInfo dpi)
            : base(elementViewModel)
        {
            _dpi = dpi;
            _dependencyProperty = dpi.Property;
            this.Name           = dpi.DisplayName;
            _propertyInfo       = this.ElementModel.GetType().GetRuntimeProperty(dpi.DisplayName);

            if (_propertyInfo != null)
            {
                var accessor = _propertyInfo.GetMethod ?? _propertyInfo.SetMethod;

                _propertyType = accessor.ReturnType;
            }

            if (_propertyType == null)
            {
                this.DefaultValue =
                    _dpi.Property.GetMetadata(this.ElementModel.GetType())
                    .DefaultValue;

                _propertyType = this.DefaultValue != null?this.DefaultValue.GetType() : typeof(object);
            }

            this.CoercionHelper =
                ValueCoercionHelperFactory.GetValueCoercionHelper(this.DependencyProperty);
        }
#pragma warning disable 1998
        private async Task Build()
#pragma warning restore 1998
        {
            this.RootElements.Clear();

            var appResourcesElement = new Stubs.Application();

            this.AppViewModel = new DependencyObjectViewModel(this, null, appResourcesElement);
            this.RootElements.Add(this.AppViewModel);

            var rootElement = VisualTreeHelperExtensions.GetRealWindowRoot();

            if (rootElement != null)
            {
                var ancestors = rootElement.GetAncestors();

                var newRoot = ancestors?.OfType <UIElement>().LastOrDefault();

                if (newRoot != null)
                {
                    rootElement = newRoot;
                }

                this.RootElements.Add(new DependencyObjectViewModel(this, null, rootElement));
            }

            foreach (var popup in VisualTreeHelper.GetOpenPopups(Window.Current))
            {
                this.RootElements.Add(new DependencyObjectViewModel(this, null, popup));
            }
        }
Esempio n. 3
0
 public BasePropertyViewModel(DependencyObjectViewModel elementModel)
 {
     this.ElementModel      = elementModel;
     this.ResetValueCommand = new RelayCommand(
         this.ResetValue,
         () => this.CanResetValue);
     this.AnalyzeCommand = new RelayCommand(
         this.Analyze,
         () => this.CanAnalyze);
     this.FindSimilarCommand = new RelayCommand(
         this.FindSimilar,
         () => this.CanFindSimilar);
     this.PropertyChanged += OnPropertyChanged;
 }
        private void OnSelectedItemChanged(
            DependencyObjectViewModel oldSelectedItem,
            DependencyObjectViewModel newSelectedItem)
        {
            if (oldSelectedItem != null)
            {
                oldSelectedItem.ModelPropertyChanged -= OnModelPropertyChanged;
            }

            if (newSelectedItem != null)
            {
                newSelectedItem.ModelPropertyChanged += OnModelPropertyChanged;
#pragma warning disable 4014
                newSelectedItem.LoadPropertiesAsync();
#pragma warning restore 4014
            }

            UpdateHighlight();
        }
 public PropertyViewModel(DependencyObjectViewModel elementViewModel, PropertyInfo propertyInfo)
     : base(elementViewModel)
 {
     _propertyInfo = propertyInfo;
     this.Name     = propertyInfo.Name;
 }