Databinding HelixView (MVVM)

Apr 21, 2011 at 3:08 PM

Hi,

I want to bind the HelixView3D to a model (MVVM design pattern). The only fully working way I found was by not using the MVVM design pattern. Since the MVVM pattern is a must and used in other all parts of the project, I want to use it also for the HelixView3D.

When I bind to the ModelVisual3D.content to its content in the model, the Viewport3DHelper doesnt work anymore. The viewport3DHelper doesn't detected a Visual3D which is near the clicked point. When I check the VisualChildernCount, its shows me one child.

I think the VisualChild isn't the child (3D Model) which I am clicking on. I guess its an ambientlight visual....

Regards

VuurVOS

 

Apr 25, 2011 at 7:54 PM

try adding this to HelixView3D:

protected override void OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)

        {
            //base.OnItemsChanged(e);
           switch (e.Action)
            {
                case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                    Add(e.NewItems.ToList<Visual3D>());
                    break;
                case System.Collections.Specialized.NotifyCollectionChangedAction.Move:
                    break;
                case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
                    Remove(e.OldItems.ToList<Visual3D>());
                    break;
                case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
                    break;
                case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
                    ClearChildren();
                    break;
                default:
                    break;
            }
        }
works like a charm for me - it's not fully implemented, obviously - but I think you get the idea

Coordinator
Jun 19, 2011 at 11:27 AM

vuurvos: I added a MvvmDemo that binds to HelixVis3D.ItemsSource. Adding new Visual3Ds should work now. (In the past I have used to add Visual3Ds in the XAML and bind to Model3Ds in the ViewModels)

zeux: thanks for pointing out the missing code! I added it to HelixView3D with some modifications (seems like you have added different Add/Remove methods) The implementation of Move and Replace is also remaining, as you point out.  

The MvvmDemo is not complete, will add more when I learn more Caliburn.Micro...