Using of 3DTools inside of UserControl

Topics: Developer Forum, User Forum
Feb 25, 2007 at 8:57 AM
Edited Feb 25, 2007 at 8:57 AM

I inspired by your Channel9Demo and tried to create my UserControl. It would be a ButtonWithTwoFaces.

What is a problem? It looks, that 3D tranformations I've defined, are not applied, because when I build and run it, there is only second button visible (it overlaps the first one). When I comment out the second one (and its material, transformation and so on), first button is shown correctly. When I set up my dependency property AngleOfRotation to for example 30 degrees, it does not affect the viewport.

BUT: If i test my xaml and codebehind not as UserControl, but directly inside of Window, it works correctly...

Is there any limitation of using 3DTools in a UserControl? Or is there any aother problem?

Thank you.


Here is my XAML:

<UserControl x:Class="Channel9Demo.ButtonWithTwoFaces"


<cvrt:ArithmeticConvertor x:Key="arithConvertor" />

<!-- Visuals -->

<Button x:Key="Visual1" Width="120" Height="90" Click="ButtonClick" Content="First face">

<Button x:Key="Visual2" Width="120" Height="90" Click="ButtonClick" Content="Second face">

<!-- 3D Transforms-->
<Transform3DGroup x:Key="Transform1" x:Name="Transform1">
<AxisAngleRotation3D Angle="{Binding ElementName=MyDecorator, Path=AngleOfRotation}" Axis="0 1 0" />

<Transform3DGroup x:Key="Transform2">
<AxisAngleRotation3D Axis="0 1 0">
<Binding ElementName="MyDecorator" Path="AngleOfRotation" Converter="{StaticResource arithConvertor}" ConverterParameter="-180"/>

<!-- 3D Models -->
<MeshGeometry3D x:Key="PlaneMesh" Positions="-4,3,0 -4,-3,0 4,-3,0 4,3,0" TextureCoordinates="0,0 0,1 1,1 1,0" TriangleIndices="0 1 2 0 2 3"/>

<!-- Materials -->
<DiffuseMaterial x:Key="Material1">
<VisualBrush Visual="{StaticResource Visual1}"/>

<DiffuseMaterial x:Key="Material2">
<VisualBrush Visual="{StaticResource Visual2}"/>

<!--Decorator styler-->

<Style TargetType="local:Interactive3DDecorator" x:Key="3DDecoratorStyler">
<Setter Property="own:OwnPropertiesOfInteractive3DDecorator.AngleOfRotation"


<local:Interactive3DDecorator Name="MyDecorator" Style="{StaticResource 3DDecoratorStyler}">
<Viewport3D Width="240" Height="180">

<PerspectiveCamera FieldOfView="90" Position="0, 0, 4" LookDirection="0, 0, -1"/>

<local:InteractiveVisual3D Transform="{StaticResource Transform1}"
Geometry="{StaticResource PlaneMesh}"
Visual="{StaticResource Visual1}" />

<local:InteractiveVisual3D Transform="{StaticResource Transform2}"
Geometry="{StaticResource PlaneMesh}"
Visual="{StaticResource Visual2}" />

<DirectionalLight Color="#FFFFFFFF" Direction="0,-1,-2"/>

And here is definition of dependency property:

public class OwnPropertiesOfInteractive3DDecorator
: _3DTools.Interactive3DDecorator

public OwnPropertiesOfInteractive3DDecorator()
: base()

static OwnPropertiesOfInteractive3DDecorator()
AngleOfRotationProperty = DependencyProperty.Register("AngleOfRotation", typeof(Double), typeof(_3DTools.Interactive3DDecorator), new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsRender));
catch (ArgumentException)

public Double AngleOfRotation
get { return (Double)this.GetValue(AngleOfRotationProperty); }
set { this.SetValue(AngleOfRotationProperty, value); }

public static readonly DependencyProperty AngleOfRotationProperty;

Mar 20, 2007 at 7:41 PM
Have you been able to get this working? I just tried out something myself, and it seemed like UserControls were ok. I didn't have your full source, so I had to comment out your dependency property and converter code, so I'm not sure if those are causing problems. Are you sure you're setting all of these values up correctly - I imagine it could be an issue with something not being correct with the converter or dependency property.