I'd like to know how to programmatically set the WPF Dependecy Property Viewport2DVisual3D.IsVisualHostMaterialProperty .
In the xaml I would use:
<Viewport2DVisual3D>
<Viewport2DVisual3D.Geometry>
<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"/>
</Viewport2DVisual3D.Geometry>
<Viewport2DVisual3D.Material>
<DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
</Viewport2DVisual3D.Material>
<Viewport2DVisual3D.Visual>
<Grid>
<Image Source="{StaticResource BG}"/>
</Grid>
</Viewport2DVisual3D.Visual>
</Viewport2DVisual3D>
But how can it be done in code behind?
How to create an attached property. If your class defines an attached property solely for use by other types, then your class doesn't need to derive from DependencyObject. Otherwise, follow the WPF model of having an attached property also be a dependency property, by deriving your class from DependencyObject .
Attached property is property that has been seized pursuant to a court order, either as a provisional pre-judgment remedy or for the enforcement of a final judgment. Property may be attached only after the commencement of a lawsuit.
Attached properties are properties which can be set on any wpf object (basically, at least a DependencyObject) via the DependencyObject. SetValue method. The purpose for this mechanism is to "attach" to other objects information needed by parent objects, not the child objects themselves. For example, the Grid.
It's fairly simple
just give the DiffuseMaterial a name
<Viewport2DVisual3D>
<Viewport2DVisual3D.Geometry>
<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" />
</Viewport2DVisual3D.Geometry>
<Viewport2DVisual3D.Material>
<DiffuseMaterial x:Name="diffuse" />
</Viewport2DVisual3D.Material>
<Viewport2DVisual3D.Visual>
<Grid>
<Image Source="{StaticResource BG}" />
</Grid>
</Viewport2DVisual3D.Visual>
</Viewport2DVisual3D>
in code
set it like this
diffuse.SetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty, true);
or
Viewport2DVisual3D.SetIsVisualHostMaterial(diffuse, true);
the property Viewport2DVisual3D.IsVisualHostMaterialProperty
is an attached property which can be set in the above mentioned ways
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With