Viewport3D
2 つの照明条件を交互に切り替えたい があります。各ライト条件は、Model3DGroup
1 つまたは複数のライト ( 、 など) を含むDirectionalLight
にAmbientLight
なります。
を使用する予定ですが、直接の親 ( ) にはプロパティがないDataTrigger
ため、どのオブジェクトとどのプロパティを使用すればよいかわかりません。以下のコードのように、それ自体でプロパティを使用すると、ターゲットが認識されません。Model3DGroup
ModelVisual3D
Style
Style
Viewport3D
Setter.TargetName
<CheckBox x:Name="shadows" Content="Shadows" />
<Viewport3D>
<Viewport3D.Resources>
<Model3DCollection x:Key="shaded_light">
<DirectionalLight Color="White" Direction="-1,-1, -10" />
</Model3DCollection>
<Model3DCollection x:Key="solid_light">
<AmbientLight Color="White" />
</Model3DCollection>
</Viewport3D.Resources>
<Viewport3D.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=shadows, Path=IsChecked}" Value="True">
<!-- The setter below doesn't work: "The name 'lightsource' is not recognized" -->
<Setter TargetName="lightsource" Property="Content" Value="{StaticResource shaded_light}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Viewport3D.Style>
<Viewport3D.Camera>
<OrthographicCamera LookDirection="0,0,-1" Position="0,0,500" UpDirection="0,1,0" Width="400"/>
</Viewport3D.Camera>
<ModelVisual3D x:Name="lightsource">
<ModelVisual3D.Content>
<Model3DGroup Children="{StaticResource solid_light}" />
</ModelVisual3D.Content>
</ModelVisual3D>
(...)