/// <summary>
        /// Initializes a new instance of the <see cref="BindingEditorWindow"/> class.
        /// </summary>
        /// <param name="propertyItem">The property item.</param>
        public BindingEditorWindow(PropertyItem propertyItem)
        {
            InitializeComponent();
            _viewModel = new BindingEditorViewModel(propertyItem);
            DataContext = _viewModel;

            tree.SelectedItemChanged += (s, e) => _viewModel.SelectedPathItem = (PathItem)tree.SelectedValue;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ResourcesEditorViewModel"/> class.
        /// </summary>
        /// <param name="propertyItem">The property item.</param>
        public ResourcesEditorViewModel(PropertyItem propertyItem)
        {
            _propertyItem = propertyItem;

            var fe = propertyItem.Instance as FrameworkElement;
            if (fe != null)
            {
                _resources.AddRange(ResourceItemFactory.GetResourcesForElement(fe));
            }

            Resources = new ListCollectionView(_resources);
            Resources.Filter = FilterResources;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BindingEditorViewModel"/> class.
        /// </summary>
        /// <param name="propertyItem">The property item.</param>
        public BindingEditorViewModel(PropertyItem propertyItem)
        {
            _instance = (DependencyObject)propertyItem.Instance;

            Sources = new ListCollectionView(Enum.GetValues(typeof(BindingSource)));
            Sources.MoveCurrentToFirst();
            Sources.CurrentChanged += (s, e) => OnSourceChanged();

            Modes = new ListCollectionView(Enum.GetValues(typeof(BindingMode)));
            Modes.MoveCurrentToFirst();
            Modes.CurrentChanged += (s, e) => UpdateBinding();

            UpdateSourceTriggers = new ListCollectionView(Enum.GetValues(typeof (UpdateSourceTrigger)));
            UpdateSourceTriggers.MoveCurrentToFirst();
            UpdateSourceTriggers.CurrentChanged += (s, e) => UpdateBinding();

            SourceList = new ListCollectionView(_pathItems);
            BuildSourceTree();

            _dpd = DependencyPropertyDescriptor.FromProperty(propertyItem.Property);

            _binding  = BindingOperations.GetBinding((DependencyObject) propertyItem.Instance, _dpd.DependencyProperty);
            if (_binding == null)
            {
                UpdateBinding();
            }
            else
            {
                if( _binding.Source == null )
                {
                    Sources.MoveCurrentTo(BindingSource.DataContext);
                }
                else if( _binding.RelativeSource != null )
                {
                    if( _binding.RelativeSource.Mode == RelativeSourceMode.PreviousData )
                    {
                        Sources.MoveCurrentTo(BindingSource.PreviousData);
                    }
                    else if( _binding.RelativeSource.Mode == RelativeSourceMode.TemplatedParent)
                    {
                        Sources.MoveCurrentTo(BindingSource.TemplatedParent);
                    }
                    else if( _binding.RelativeSource.Mode == RelativeSourceMode.FindAncestor)
                    {
                        Sources.MoveCurrentTo(BindingSource.FindAncestor);
                    }
                }
                UpdateExpression();
            }
        }
Exemplo n.º 4
0
 public ResourceEditor(PropertyItem propertyItem)
 {
     InitializeComponent();
     _viewModel = new ResourcesEditorViewModel(propertyItem);
     DataContext = _viewModel;
 }