Bonjour,

Je suis en train de développer un UserControl WPF qui sera inséré dans une WinForm.
Le Usercontrol est la représentation d'un cube en 3D que je veux déplaçable en XYZ soit par curseurs, soit par valeurs.

Le cube, ses transformations 3D et un storyboard sont en XAML car j'envisage par la suite l'ajout d'autres objets et animations.

Je bute sur la modification des From/To/By à partir du code behind.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  Private Sub Bouton_Click(sender As Object, e As RoutedEventArgs) Handles Bouton.Click
 
   'Positionnement du cube au centre
    translateX.OffsetX = 0
    translateY.OffsetY = 0
    translateZ.OffsetZ = 0
 
    Dim sequ_anim As New Storyboard
 
    Dim myDoubleAnimation As New DoubleAnimation()
    myDoubleAnimation.By = 5
    myDoubleAnimation.Duration = New Duration(TimeSpan.FromSeconds(5))
 
    Storyboard.SetTargetName(myDoubleAnimation, "translateX")
    Storyboard.SetTargetProperty(myDoubleAnimation, New PropertyPath("OffsetX"))
    sequ_anim.Children.Add(myDoubleAnimation)
 
    sequ_anim.Begin()
 
  End Sub
Le XAML est :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<UserControl x:Class="UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="600">
 
    <Grid  x:Name="grid1"  Background="LightGreen"   >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="200"/>
        </Grid.ColumnDefinitions>
 
        <!-- Place a Label control at the top of the view. -->
        <Label x:Name="label1"    
               HorizontalAlignment="left" VerticalAlignment="Top"
               TextBlock.TextAlignment="Left" FontSize="20" Foreground="Blue"  
               Content="CUBE : Déplacements XYZ" 
               Grid.Column="0" Grid.Row="0"
               />
 
        <!-- Viewport3D is the rendering surface. -->
        <Viewport3D x:Name="Viewport1"
                    Grid.Column="0"  Margin="0,0,0,0" >
 
            <Viewport3D.RenderTransform>
                <TransformGroup  x:Name="group1">
                    <ScaleTransform ScaleX="1" ScaleY="1"/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Viewport3D.RenderTransform>
 
            <!-- Ajout d'une camera. -->
            <Viewport3D.Camera>
                <PerspectiveCamera  x:Name="camera1"
                    Position="-70,-70,70" 
                    LookDirection="70,70,-70 "
                    UpDirection="1,1,0" />
            </Viewport3D.Camera>
 
            <!-- Ajout des modèles. -->
            <ModelVisual3D x:Name="ScenePrincipale" >
                <ModelVisual3D.Content >
                    <Model3DGroup>
                        <!--Eclairages, MeshGeometry3D et DiffuseMaterial sont ajoutés au ModelVisual3D.-->
                        <DirectionalLight Color="White"  Direction="-100,-100,-100" />
                        <!--<AmbientLight Color="White" x:Name="Eclairage1" />-->
 
                        <!-- Défini le plan de travail. -->
                        <GeometryModel3D  x:Name="plan" >
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D Positions="30,30,0    -30,30,0  -30,-30,0    30,-30,0"
                                                TriangleIndices="0 1 2   2 3 0"  />
                            </GeometryModel3D.Geometry>
                            <GeometryModel3D.Material>
                                <DiffuseMaterial>
                                    <DiffuseMaterial.Brush>
                                        <SolidColorBrush 
                                           Color="WhiteSmoke" 
                                           Opacity="1.0"/>
                                    </DiffuseMaterial.Brush>
                                </DiffuseMaterial>
                            </GeometryModel3D.Material>
                            <GeometryModel3D.BackMaterial >
                                <DiffuseMaterial>
                                    <DiffuseMaterial.Brush>
                                        <SolidColorBrush 
                                           Color="LightYellow" 
                                           Opacity="1.0"/>
                                    </DiffuseMaterial.Brush>
                                </DiffuseMaterial>
                            </GeometryModel3D.BackMaterial>
                        </GeometryModel3D>
 
                    </Model3DGroup>
                </ModelVisual3D.Content>
            </ModelVisual3D>
 
            <ModelVisual3D x:Name="Objets">
                <ModelVisual3D.Content>
                    <Model3DGroup>
                        <!-- Defini un cube rouge. -->
                        <GeometryModel3D  x:Name="Cube1">
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D Positions="0,0,0   10,0,0   10,10,0   0,10,0 
                                                0,0,10   10,0,10   10,10,10   0,10,10"
                                                TriangleIndices="0 3 1   1 3 2   0 4 3   4 7 3   4 6 7  
                                                4 5 6  0 1 4   1 5 4   1 2 6   6 5 1   2 3 7   7 6 2 "/>
                            </GeometryModel3D.Geometry>
                            <GeometryModel3D.Material>
                                <DiffuseMaterial>
                                    <DiffuseMaterial.Brush>
                                        <SolidColorBrush 
                                           Color="Red" 
                                           Opacity="1.0"
                                           />
                                    </DiffuseMaterial.Brush>
                                </DiffuseMaterial>
                            </GeometryModel3D.Material>
                        </GeometryModel3D>
                    </Model3DGroup>
                </ModelVisual3D.Content>
 
                <ModelVisual3D.Transform>
                    <Transform3DGroup>
                        <!-- Translation suivant X. -->
                        <TranslateTransform3D x:Name="translateX"  />
                        <!-- Translation suivant Y. -->
                        <TranslateTransform3D x:Name="translateY"  />
                        <!-- Translation suivant Z. -->
                        <TranslateTransform3D x:Name="translateZ"  />
                    </Transform3DGroup>
                </ModelVisual3D.Transform>
            </ModelVisual3D>
 
            <Viewport3D.Resources>
                <Storyboard x:Key="story_transl"  
                            Storyboard.TargetName="cube_deplct">
 
                    <!--Déplacements en X, Y et Z (dans le même temps)-->
                    <DoubleAnimation 
                                Storyboard.TargetName="translateX" 
                                Storyboard.TargetProperty="OffsetX"
                                To ="5" Duration="0:0:2"  BeginTime=" 00:00:00"
                                AutoReverse="False"  FillBehavior="HoldEnd" />
 
                    <DoubleAnimation
                                Storyboard.TargetName="translateY" 
                                Storyboard.TargetProperty="OffsetY" 
                                To ="5" Duration="0:0:2"  BeginTime=" 00:00:02"
                                AutoReverse="False"   FillBehavior="HoldEnd" />
 
                    <DoubleAnimation
                                Storyboard.TargetName="translateZ" 
                                Storyboard.TargetProperty="OffsetZ" 
                                To ="5" Duration="0:0:2"  BeginTime=" 00:00:04"
                                AutoReverse="False"  FillBehavior="HoldEnd" />
                </Storyboard>
            </Viewport3D.Resources>
        </Viewport3D>
 
 
        <Slider x:Name = "sliderTranslX"
                Grid.Column="1"  HorizontalAlignment="Center"  VerticalAlignment="Top"
                Width="100" Height="20"
                Margin="0,200,0,0" 
                Minimum =" -50" Maximum = "50" 
                Value = "{Binding ElementName=translateX, Path=OffsetX }" 
                ToolTip="Translation en X"  />
 
        <Slider x:Name = "sliderTranslY"
                Grid.Column="1"  HorizontalAlignment="Center"  VerticalAlignment="Top"
                Width="100" Height="20"
                Margin="0,230,0,0" 
                Minimum =" -50" Maximum = "50" 
                Value = "{Binding ElementName=translateY, Path=OffsetY }" 
                ToolTip="Translation en Y"  />
 
        <Slider x:Name = "sliderTranslZ"
                Grid.Column="1"  HorizontalAlignment="Center"  VerticalAlignment="Top"
                Width="100" Height="20"
                Margin="0,260,0,0" 
                Minimum =" -50" Maximum = "50" 
                Value = "{Binding ElementName=translateZ, Path=OffsetZ }" 
                ToolTip="Translation en Z" />
 
        <Slider x:Name = "sliderZoomCamera"
                Grid.Column="1"  HorizontalAlignment="Center"  VerticalAlignment="Top"
                Width="100" Height="20"
                Margin="0,330,0,0" 
                Minimum =" 10" Maximum = "80" 
                Value = "{Binding ElementName = camera1  , Path=FieldOfView }" 
                ToolTip="Zoom de la caméra"  />
 
        <Button x:Name = "Bouton"     Content="Button"    Click="Bouton_Click"
                Grid.Column="1"  HorizontalAlignment="Center"  VerticalAlignment="Top"
                Width="80" Height="20"
                Margin="0,410,0,0" 
                IsEnabled="True"
                >
        </Button>
 
 
    </Grid>
 
 
</UserControl>

J'ai l'erreur suivant
System.InvalidOperationException: 'Aucune portée de nom applicable n'existe pour résoudre le nom 'translateX'.'


Je ne vois pas mon pb...


Merci de votre lecture