Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selection dependency property in DrawingControl 3D collectionChanged #194

Open
Pedrodeo opened this issue Nov 4, 2022 · 0 comments
Open

Comments

@Pedrodeo
Copy link

Pedrodeo commented Nov 4, 2022

Hello,
In the DrawingControl3D, there is a DependencyProperty Selection which is an EntitySelection, as I understand, a collection of Entities :

public EntitySelection Selection
		{
			get { return (EntitySelection)GetValue(SelectionProperty); }
			set { SetValue(SelectionProperty, value); }
		}


		public static readonly DependencyProperty SelectionProperty = DependencyProperty.Register("Selection",
			typeof(EntitySelection), typeof(DrawingControl3D), new PropertyMetadata(OnSelectionChanged));

		private static void OnSelectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			var d3D = d as DrawingControl3D;
			if (d3D == null)
				return;

			var newVal = e.NewValue as EntitySelection;

			d3D.ReplaceSelection(newVal);
		}

This Selection is usefull in multiselection cases, to bind the collection of selected entities between the treeview part of the explorer, and the DrawingControl3D for example.

When the Selection is set, the event OnSelectionChanged is raised, but we never subscribe to the OnCollectionChanged event of the Selection, which means that if an Entity is added or removed to the Selection, no event will be raised and the binding fails.
Same in the OnSelectedEntityChanged event, the Selection is Cleared but it doesn't raised any event and so the selected Entities stay selected in the DrawingControl3D.

I would do something like this :

            var newVal = e.NewValue as EntitySelection;
            var oldVal = e.OldValue as EntitySelection;

            if (newVal != null)
            {
                newVal.CollectionChanged += d3D.OnSelectionCollectionChanged;
            }

            if (oldVal != null)
            {
                oldVal.CollectionChanged -= d3D.OnSelectionCollectionChanged;
            }

and update the Highlight in the OnSelectionCollectionChanged.

What do you think ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant