2012-02-11 44 views
0

我在窗口上有一些3D元素,我想在某個時刻刪除一切,並重新開始,我該怎麼做? 我有這樣的XAML:如何從風中移除ModelUIElement3D和Viewport2DVisual3D

<tools:TrackballDecorator> 
    <Viewport3D x:Name="_Main3D" 
       ClipToBounds="False" 
       Camera="{StaticResource Other3D_MainCamera}"> 

     <!-- ModelVisual3D containing the lights --> 
     <StaticResource ResourceKey="Other3D_Lights" /> 

     <!-- 
      Clickable 3D models (ModelUIElement3D): Cover, spine and edges 
      They will work as if they were one object, so I'll use only one ModelUIElement3D to hold them and wire up their events. 
     --> 
     <ModelUIElement3D MouseDown="Cover_MouseDown" x:Name="Book"> 
      <ModelUIElement3D.Model> 
       <Model3DGroup> 
        <GeometryModel3D x:Name="_FrontCover" 
            Geometry="{StaticResource MeshGeometry3D_Cover}" 
            Material="{StaticResource Material_FrontCover}" 
            Transform="{StaticResource Transform3D_FrontCover}" /> 
        <GeometryModel3D x:Name="_BackCover" 
            Geometry="{StaticResource MeshGeometry3D_Cover}" 
            Material="{StaticResource Material_Cover}" 
            Transform="{StaticResource Transform3D_BackCover}" /> 
        <GeometryModel3D x:Name="_SpineCover" 
            Geometry="{StaticResource MeshGeometry3D_Cover}" 
            Material="{StaticResource Material_Cover}" 
            Transform="{StaticResource Transform3D_SpineCover}" /> 
        <GeometryModel3D x:Name="_LeftEdge" 
            Geometry="{StaticResource MeshGeometry3D_Edge}" 
            Material="{StaticResource Material_Edge}" 
            Transform="{StaticResource Transform3D_Left}" /> 
        <GeometryModel3D x:Name="_RightEdge" 
            Geometry="{StaticResource MeshGeometry3D_Edge}" 
            Material="{StaticResource Material_Edge}" 
            Transform="{StaticResource Transform3D_Right}" /> 
       </Model3DGroup> 
      </ModelUIElement3D.Model> 
     </ModelUIElement3D> 

     <!-- Interactive 3D models: Pages --> 

     <Viewport2DVisual3D x:Name="_LeftPage" 
          Geometry="{StaticResource MeshGeometry3D_Plane}" 
          Transform="{StaticResource Transform3D_Left}"> 
      <Viewport2DVisual3D.Material> 
       <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" /> 
      </Viewport2DVisual3D.Material> 
      <Viewport2DVisual3D.Visual> 
       <Image Source="C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center" /> 

      </Viewport2DVisual3D.Visual> 
     </Viewport2DVisual3D> 


     <Viewport2DVisual3D x:Name="_RightPage" 
          Geometry="{StaticResource MeshGeometry3D_Plane}" 
          Transform="{StaticResource Transform3D_Right}"> 
      <Viewport2DVisual3D.Material> 
       <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" /> 
      </Viewport2DVisual3D.Material> 
      <Viewport2DVisual3D.Visual> 
       <!-- 
       <TextBox Style="{StaticResource Control_PagesStyle}" 
         Padding="5,30,30,30" 
         MouseDoubleClick="Page_MouseDoubleClick" /> 
       --> 
       <!-- The TextBox above was replaced by an InkCanvas --> 
       <InkCanvas Style="{StaticResource Control_InkCanvasStyle}" PreviewMouseRightButtonDown="InkCanvas_PreviewMouseRightButtonDown"/> 
      </Viewport2DVisual3D.Visual> 
     </Viewport2DVisual3D> 

    </Viewport3D> 
</tools:TrackballDecorator> 

但是當我嘗試做

_LayoutRoot.Children.Remove() 

它不允許它,因爲他們不是UI元素。 任何幫助嗎?

+0

有人嗎?我無望在這裏:( – 2012-02-11 20:18:16

回答

0

已解決, 已使用: _LayoutRoot.Children.Clear();

它工作。

Clear()刪除網格中的所有元素, 並使其爲垃圾收集做好準備。 希望這可以幫助別人。