本文介绍了如何以编程方式设置附加属性,例如Viewport2DVisual3D.IsVisualHostMaterialProperty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何以编程方式设置WPF Dependecy属性Viewport2DVisual3D.IsVisualHostMaterialProperty.
I'd like to know how to programmatically set the WPF Dependecy Property Viewport2DVisual3D.IsVisualHostMaterialProperty .
在xaml中,我将使用:
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?
推荐答案
这很简单
只需给DiffuseMaterial命名
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>
用代码
像这样设置
diffuse.SetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty, true);
或
Viewport2DVisual3D.SetIsVisualHostMaterial(diffuse, true);
Viewport2DVisual3D.IsVisualHostMaterialProperty
属性是可以通过上述方式设置的附加属性
the property Viewport2DVisual3D.IsVisualHostMaterialProperty
is an attached property which can be set in the above mentioned ways
这篇关于如何以编程方式设置附加属性,例如Viewport2DVisual3D.IsVisualHostMaterialProperty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!