added samples
[windows-sources.git] / sdk / samples / WPFSamples / Postcard3D / visualbasic / postcard3d.xaml
blob46fa3f0af52d58c70a35e756f098e99adc8b4060
1 <Page x:Class="SamplePage"
2     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4     xmlns:my="clr-namespace:Postcard3D"
5     Title="Postcard3D" Background="{StaticResource GoldenBrownGradient}">
6   <Viewbox Margin="0,20,0,0">
7     <Grid>
8       <Grid.RowDefinitions>
9         <RowDefinition/>
10         <RowDefinition MinHeight="440"/>
11       </Grid.RowDefinitions>
12       <Grid Grid.Row="0">
13         <Grid.ColumnDefinitions>
14           <ColumnDefinition/>
15           <ColumnDefinition/>
16         </Grid.ColumnDefinitions>
18         <!-- High Contrast InkCanvas for rendering ink onto the photo -->
19         <my:HighContrastInkCanvas x:Name="icFront" Grid.Column="0" Width="400" Height="300" >
20           <Grid Width="{Binding ElementName=icFront,Path=Width}" Height="{Binding ElementName=icFront,Path=Height}">
21             <Border BorderBrush="White" BorderThickness="5" >
22               <Image Source="seattle_rainier.jpg"/>
23             </Border>
24           </Grid>
25         </my:HighContrastInkCanvas>
27         <!-- Regular InkCanvas for rendering ink onto the backside of the postcard -->
28         <InkCanvas Name="icBack" Grid.Column="1"
29                    Width="{Binding ElementName=icFront,Path=Width}"
30                    Height="{Binding ElementName=icFront,Path=Height}">
31           <InkCanvas.DefaultDrawingAttributes>
32             <DrawingAttributes Color="Blue" Width="1" Height="1"/>
33           </InkCanvas.DefaultDrawingAttributes>
34           <Border BorderBrush="LightGray" BorderThickness="2"
35                   Width="{Binding ElementName=icBack,Path=Width}"
36                   Height="{Binding ElementName=icBack,Path=Height}">
37             <Grid Background="WhiteSmoke" >
38               <Grid.ColumnDefinitions>
39                 <ColumnDefinition Width="*"/>
40                 <ColumnDefinition Width="*"/>
41               </Grid.ColumnDefinitions>
42               <Grid.RowDefinitions>
43                 <RowDefinition Height="100"/>
44                 <RowDefinition />
45               </Grid.RowDefinitions>
46               <Image HorizontalAlignment="Right" Margin="10,10" Grid.Column="1" Grid.Row="0" Source="stamp.jpg"/>
47               <TextBlock FontSize="18" Margin="10,0" Grid.Column="1" Grid.Row="2">To:</TextBlock>
48               <Line X1="10" Y1="80" X2="190" Y2="80" Stroke="Gray" StrokeThickness="1" Grid.Column="1" Grid.Row="2"/>
49               <Line X1="10" Y1="130" X2="190" Y2="130" Stroke="Gray" StrokeThickness="1" Grid.Column="1" Grid.Row="2"/>
50               <Line X1="10" Y1="180" X2="190" Y2="180" Stroke="Gray" StrokeThickness="1" Grid.Column="1" Grid.Row="2"/>
51               <Line X1="0" Y1="0" X2="0" Y2="300" Stroke="LightGray" StrokeThickness="1" Grid.Column="1" Grid.Row="0" Grid.RowSpan="2"/>
52             </Grid>
53           </Border>
54         </InkCanvas>
56       </Grid>
57       <Grid Grid.Row="1">
58         <Grid.ColumnDefinitions>
59           <ColumnDefinition />
60           <ColumnDefinition MinWidth="200"/>
61         </Grid.ColumnDefinitions>
63         <!-- StackPanel with a couple of elements to control the Postcard -->
64         <StackPanel Grid.Column="1" Margin="20,20" HorizontalAlignment="Center" VerticalAlignment="Center">
65           <WrapPanel HorizontalAlignment="Right">
66             <Label HorizontalAlignment="Left">Rotate X</Label>
67             <Slider Name="sliderX" Minimum="0" Maximum="360" Value="150" MinWidth="180"/>
68           </WrapPanel>
69           <WrapPanel HorizontalAlignment="Right">
70             <Label HorizontalAlignment="Left">Rotate Y</Label>
71             <Slider Name="sliderY" Minimum="0" Maximum="360" Value="150" MinWidth="180"/>
72           </WrapPanel>
73           <WrapPanel HorizontalAlignment="Right">
74             <Label HorizontalAlignment="Left">Rotate Z</Label>
75             <Slider Name="sliderZ" Minimum="0" Maximum="360" Value="180" MinWidth="180"/>
76           </WrapPanel>
77           <WrapPanel HorizontalAlignment="Right">
78             <Label HorizontalAlignment="Left">Zoom</Label>
79             <Slider Name="sliderScale" Minimum="0.1" Maximum="3" Value="1.3" MinWidth="180"/>
80           </WrapPanel>
81           <Rectangle Height="15"/>
82           <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
83             <Button Margin="2,2" Name="startButton" IsEnabled="True">Start Animation</Button>
84             <Button Margin="2,2" Name="stopButton" IsEnabled="False">Stop Animation</Button>
85           </StackPanel>
86           <Rectangle Height="15"/>
87         </StackPanel>
89         <Viewbox Grid.Column="0">
90           <Viewbox.RenderTransform>
91             <ScaleTransform ScaleX  = "{Binding ElementName=sliderScale,Path=Value}"
92                             ScaleY  = "{Binding ElementName=sliderScale,Path=Value}"
93                             CenterX = "200"
94                             CenterY = "300"/>
95           </Viewbox.RenderTransform>
97           <!-- Viewport3D to host the 3D model of the Postcard -->
98           <Viewport3D Width="600" Height="400">
99             <Viewport3D.Camera>
100               <PerspectiveCamera LookDirection = "0,0,-1"
101                                  UpDirection   = "0,1,0"
102                                  Position      = "0,0,3"
103                                  FieldOfView   = "45"/>
104             </Viewport3D.Camera>
105             <ModelVisual3D>
106               <ModelVisual3D.Children>
107                 <ModelVisual3D>
108                   <ModelVisual3D.Content>
109                     <DirectionalLight Color="#FFFFFF" Direction="0,0,-1"/>
110                   </ModelVisual3D.Content>
111                 </ModelVisual3D>
112                 <ModelVisual3D>
113                   <ModelVisual3D.Content>
114                     <DirectionalLight Color="#FFFFFF" Direction="0,0,1"/>
115                   </ModelVisual3D.Content>
116                 </ModelVisual3D>
117                 <ModelVisual3D>
118                   <ModelVisual3D.Content>
119                     <GeometryModel3D>
120                       <GeometryModel3D.Geometry>
121                         <MeshGeometry3D TriangleIndices    = "0,1,2 3,4,5"
122                                         Normals            = "0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1"
123                                         TextureCoordinates = "0,0 1,0 1,1 1,1 0,1 0,0"
124                                         Positions          = "-0.66,-0.5,0 0.66,-0.5,0 0.66,0.5,0 0.66,0.5,0 -0.66,0.5,0 -0.66,-0.5,0"/>
125                       </GeometryModel3D.Geometry>
126                       <GeometryModel3D.Material>
127                         <DiffuseMaterial>
128                           <DiffuseMaterial.Brush>
129                             <VisualBrush Visual="{Binding ElementName=icFront}">
130                               <VisualBrush.RelativeTransform>
131                                 <TransformGroup>
132                                   <ScaleTransform ScaleX="1" ScaleY="-1"/>
133                                   <TranslateTransform Y="1"/>
134                                 </TransformGroup>
135                               </VisualBrush.RelativeTransform>
136                             </VisualBrush>
137                           </DiffuseMaterial.Brush>
138                         </DiffuseMaterial>
139                       </GeometryModel3D.Material>
140                     </GeometryModel3D>
141                   </ModelVisual3D.Content>
142                 </ModelVisual3D>
143                 <ModelVisual3D>
144                   <ModelVisual3D.Content>
145                     <GeometryModel3D>
146                       <GeometryModel3D.Geometry>
147                         <MeshGeometry3D TriangleIndices    = "0,1,2 3,4,5"
148                                         Normals            = "0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1"
149                                         TextureCoordinates = "1,0 1,1 0,1 0,1 0,0 1,0"
150                                         Positions          = "-0.66,-0.5,0 -0.66,0.5,0 0.66,0.5,0 0.66,0.5,0 0.66,-0.5,0 -0.66,-0.5,0"/>
151                       </GeometryModel3D.Geometry>
152                       <GeometryModel3D.Material>
153                         <DiffuseMaterial>
154                           <DiffuseMaterial.Brush>
155                             <VisualBrush Visual="{Binding ElementName=icBack}">
156                               <VisualBrush.RelativeTransform>
157                                 <TransformGroup>
158                                   <ScaleTransform ScaleX="1" ScaleY="-1"/>
159                                   <TranslateTransform Y="1"/>
160                                 </TransformGroup>
161                               </VisualBrush.RelativeTransform>
162                             </VisualBrush>
163                           </DiffuseMaterial.Brush>
164                         </DiffuseMaterial>
165                       </GeometryModel3D.Material>
166                     </GeometryModel3D>
167                   </ModelVisual3D.Content>
168                 </ModelVisual3D>
169               </ModelVisual3D.Children>
170               <ModelVisual3D.Transform>
171                 <Transform3DGroup >
172                   <Transform3DGroup.Children>
173                     <RotateTransform3D>
174                       <RotateTransform3D.Rotation>
175                         <AxisAngleRotation3D x:Name = "xRotate"
176                                              Angle  = "{Binding ElementName=sliderX,Path=Value}"
177                                              Axis   = "1 0 0"/>
178                       </RotateTransform3D.Rotation>
179                     </RotateTransform3D>
180                     <RotateTransform3D>
181                       <RotateTransform3D.Rotation>
182                         <AxisAngleRotation3D x:Name = "yRotate"
183                                              Angle  = "{Binding ElementName=sliderY,Path=Value}"
184                                              Axis   = "0 1 0"/>
185                       </RotateTransform3D.Rotation>
186                     </RotateTransform3D>
187                     <RotateTransform3D>
188                       <RotateTransform3D.Rotation>
189                         <AxisAngleRotation3D x:Name = "zRotate"
190                                              Angle  = "{Binding ElementName=sliderZ,Path=Value}"
191                                              Axis   = "0 0 1"/>
192                       </RotateTransform3D.Rotation>
193                     </RotateTransform3D>
194                   </Transform3DGroup.Children>
195                 </Transform3DGroup>
196               </ModelVisual3D.Transform>
197             </ModelVisual3D>
198           </Viewport3D>
200         </Viewbox>
201       </Grid>
203       <!-- Event triggers to control the animation of the Postcard -->
204       <Grid.Triggers>
205         <EventTrigger SourceName="startButton" RoutedEvent="Button.Click">
206           <BeginStoryboard>
207             <Storyboard>
208               <BooleanAnimationUsingKeyFrames 
209                   Storyboard.TargetName="startButton"
210                   Storyboard.TargetProperty="(Button.IsEnabled)"
211                   Duration="0:0:0">
212                 <DiscreteBooleanKeyFrame Value="False" KeyTime="0:0:0" />
213               </BooleanAnimationUsingKeyFrames>
214               <BooleanAnimationUsingKeyFrames 
215                   Storyboard.TargetName="stopButton"
216                   Storyboard.TargetProperty="(Button.IsEnabled)"
217                   Duration="0:0:0">
218                 <DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0" />
219               </BooleanAnimationUsingKeyFrames>
220             </Storyboard>
221           </BeginStoryboard>
222           <BeginStoryboard Name="xRotateStoryboard">
223             <Storyboard>
224               <DoubleAnimation Storyboard.TargetName     = "xRotate" 
225                                Storyboard.TargetProperty = "Angle"
226                                From                      = "0"
227                                To                        = "360" 
228                                Duration                  = "0:0:57"
229                                RepeatBehavior            = "Forever"/>
230             </Storyboard>
231           </BeginStoryboard>
232           <BeginStoryboard Name="yRotateStoryboard">
233             <Storyboard>
234               <DoubleAnimation Storyboard.TargetName     = "yRotate" 
235                                Storyboard.TargetProperty = "Angle"
236                                From                      = "0"
237                                To                        = "360" 
238                                Duration                  = "0:0:13"
239                                RepeatBehavior            = "Forever"/>
240             </Storyboard>
241           </BeginStoryboard>
242           <BeginStoryboard Name="zRotateStoryboard">
243             <Storyboard>
244               <DoubleAnimation Storyboard.TargetName     = "zRotate" 
245                                Storyboard.TargetProperty = "Angle"
246                                From                      = "0"
247                                To                        = "360" 
248                                Duration                  = "0:0:37"
249                                RepeatBehavior            = "Forever"/>
250             </Storyboard>
251           </BeginStoryboard>
252         </EventTrigger>
253         <EventTrigger SourceName="stopButton" RoutedEvent="Button.Click">
254           <BeginStoryboard>
255             <Storyboard>
256               <BooleanAnimationUsingKeyFrames 
257                   Storyboard.TargetName="startButton"
258                   Storyboard.TargetProperty="(Button.IsEnabled)"
259                   Duration="0:0:0">
260                 <DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0" />
261               </BooleanAnimationUsingKeyFrames>
262               <BooleanAnimationUsingKeyFrames 
263                   Storyboard.TargetName="stopButton"
264                   Storyboard.TargetProperty="(Button.IsEnabled)"
265                   Duration="0:0:0">
266                 <DiscreteBooleanKeyFrame Value="False" KeyTime="0:0:0" />
267               </BooleanAnimationUsingKeyFrames>
268             </Storyboard>
269           </BeginStoryboard>
270           <StopStoryboard BeginStoryboardName="xRotateStoryboard"/>
271           <StopStoryboard BeginStoryboardName="yRotateStoryboard"/>
272           <StopStoryboard BeginStoryboardName="zRotateStoryboard"/>
273         </EventTrigger>
274       </Grid.Triggers>
275     </Grid>
276   </Viewbox>
277 </Page>