0

Databinding HelixView (MVVM)

Anonymous 10 years ago 0
This discussion was imported from CodePlex

vuurvos wrote at 2011-04-21 16:08:

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

 


zeux wrote at 2011-04-25 20:54:

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


objo wrote at 2011-06-19 12:27:

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...