title: How to set an attached property programmatically eg. Viewport2DVisual3D.IsVisualHostMaterialProperty
body: <p>I'd like to know how to programmatically set the WPF Dependecy Property Viewport2DVisual3D.IsVisualHostMaterialProperty .</p>
  
  <p>In the xaml I would use:</p>
  
  <pre><code>&lt;Viewport2DVisual3D&gt;
      &lt;Viewport2DVisual3D.Geometry&gt;
          &lt;MeshGeometry3D Positions = "0,0,0 0,-30.9274,0 0,-30.9274,-24.4287 0,0,-24.4287"
                          TextureCoordinates = "0,0 0,1 1,1 1,0"
                          TriangleIndices = "0 1 2 0 2 3"/&gt;
      &lt;/Viewport2DVisual3D.Geometry&gt;
      &lt;Viewport2DVisual3D.Material&gt;
          &lt;DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/&gt;
      &lt;/Viewport2DVisual3D.Material&gt;
  
      &lt;Viewport2DVisual3D.Visual&gt;
          &lt;Grid&gt;
              &lt;Image Source="{StaticResource BG}"/&gt;
          &lt;/Grid&gt;
      &lt;/Viewport2DVisual3D.Visual&gt;
  &lt;/Viewport2DVisual3D&gt;
  </code></pre>
  
  <p>But how can it be done in code behind?</p>