/// <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();
}
}