05-20-2016, 03:23 PM
PolyLineVisual3D.Positions takes Point3DCollection type so you cannot bind ObservableCollection<Point3D> to it.
Point3DCollection does not implement INotifyProperty changed, but it is a DependencyObject so it has changed notifications baked in.
If you set the Point3DCollection to PolyLineVisual3D.Positions, you can add points to the collection and the PolyLineVisual3D will be automatically updated. For example the following simple code can be used to test that:
This also works without any performance problems for quite some time - for me it worked very well with around 1000 positions. Of course, this cannot go forever. Therefore I am curious why you get performance problems with 50 positions - could you investigate this with performance profiler?
Though, after some positions were added, the arrow begin to become smaller and smaller. The cause of this is that the arrow cannot be smaller than one line segment.
Another problem with this approach is that it only works when you set the PolyLineVisual1.Positions in code.
Instead of this I tried to define the Binding in XAML. I tried many different ways, but I was not able to make this work - the initial line was shown (using the positions defined at the time of binding), but then the values were not updated. I am not an expert for data binding so I do not know why this happens.
WPF 3D is not very well suited for MVVM. I think that your application will work best if you would put some gluing code into the View class (though this is not very common). But I am not an expert on MVVM, so there might be some other better way to do that.
Point3DCollection does not implement INotifyProperty changed, but it is a DependencyObject so it has changed notifications baked in.
If you set the Point3DCollection to PolyLineVisual3D.Positions, you can add points to the collection and the PolyLineVisual3D will be automatically updated. For example the following simple code can be used to test that:
Code:
PolyLineVisual1.Positions = Positions;
_dispatcherTimer = new DispatcherTimer(TimeSpan.FromSeconds(0.1), DispatcherPriority.Normal, delegate (object sender, EventArgs args)
{
_index++;
Positions.Add(new Point3D(_index * 10, _index, _index * 10));
}, this.Dispatcher);
_dispatcherTimer.Start();This also works without any performance problems for quite some time - for me it worked very well with around 1000 positions. Of course, this cannot go forever. Therefore I am curious why you get performance problems with 50 positions - could you investigate this with performance profiler?
Though, after some positions were added, the arrow begin to become smaller and smaller. The cause of this is that the arrow cannot be smaller than one line segment.
Another problem with this approach is that it only works when you set the PolyLineVisual1.Positions in code.
Instead of this I tried to define the Binding in XAML. I tried many different ways, but I was not able to make this work - the initial line was shown (using the positions defined at the time of binding), but then the values were not updated. I am not an expert for data binding so I do not know why this happens.
WPF 3D is not very well suited for MVVM. I think that your application will work best if you would put some gluing code into the View class (though this is not very common). But I am not an expert on MVVM, so there might be some other better way to do that.
Andrej Benedik

