Note that there are some explanatory texts on larger screens.

plurals
  1. PODelete 3D Element from ObservableCollection
    primarykey
    data
    text
    <p>In my WPF 4.0 project, I have an ObservableCollection that contain some selected Visual3D from the view : </p> <pre><code>public ObservableCollection&lt;Visual3D&gt; SelectedElements { get { return _selectedElements; } set { if (Equals(_selectedElements, value)) { return; } _selectedElements = value; RaisePropertyChanged(() =&gt; SelectedElements); } } </code></pre> <p>Visual3D elements are selected by clicking and the source-code in the VM is : </p> <pre><code>public HitTestResultBehavior HitTestDown(HitTestResult result) { var resultMesh = result as RayMeshGeometry3DHitTestResult; if (resultMesh == null) return HitTestResultBehavior.Continue; // Obtain clicked ModelVisual3D. var vis = resultMesh.VisualHit as ModelVisual3D; if (vis != null) { Type visType = vis.GetType(); if (visType.Name == "TruncatedConeVisual3D" || visType.Name == "BoxVisual3D") { var geoModel = resultMesh.ModelHit as GeometryModel3D; if (geoModel != null) { var selecteMat = geoModel.Material as DiffuseMaterial; if (selecteMat != null) selecteMat.Brush.Opacity = selecteMat.Brush.Opacity &lt;= 0.7 ? 1 : 0.7; } // Otherwise it's a chair. Get the Transform3DGroup. var xformgrp = vis.Transform as Transform3DGroup; // This should not happen, but play it safe anyway. if (xformgrp == null) { return HitTestResultBehavior.Stop; } // Loop through the child tranforms. foreach (Transform3D t in xformgrp.Children) { // Find the TranslateTransform3D. var trans = t as TranslateTransform3D; if (trans != null) { // Define an animation for the transform. var anima = new DoubleAnimation(); if (trans.OffsetY == 0) { DependencyProperty prop = TranslateTransform3D.OffsetZProperty; if (Math.Abs(trans.OffsetZ) &lt; 2) { anima.To = 20.5*Math.Sign(trans.OffsetZ); Debug.Assert(SelectedElements != null, "SelectedElements != null"); } else { anima.To = 1*Math.Sign(trans.OffsetZ); SelectedElements.Add(vis); } // Start the animation and stop the hit-testing. trans.BeginAnimation(prop, anima); return HitTestResultBehavior.Stop; } } } } } return (HitTestResultBehavior) HitTestFilterBehavior.Continue; } </code></pre> <p>and I want to delete one or all this Visual3D element Thank you in advance </p> <p>I have implemented this methode but it's not work :</p> <pre><code>private void UnloadProduct() { if (CanUnload) { foreach (Visual3D selectedElement in SelectedElements) { if (selectedElement.DependencyObjectType.Name == "TruncatedConeVisual3D") { var test = (TruncatedConeVisual3D) selectedElement; int id = test.VisualId; ElementsCollection.RemoveAt(id); RaisePropertyChanged(() =&gt; ElementsCollection); } else { var test = (BoxVisual3D) selectedElement; int id = test.VisualId; ProductsCollection.RemoveAt(id); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload